awk - last minus one

awk - last minus one

am 18.12.2007 17:31:56 von RickM

awk -F / '/DEFINE/ { print $1 "./"$NF }' filename prints out
the pieces of a string but I now need to print the last field and the
one before it. There is no definate number fields so hardcoding to to
pick up $8 $9 might not always work. Is there something like {$NF-1}
or somethng?

Perphaps awk is not the best. Janis sent me a solution for the last
only:

sed 's, /.*/, ./,' < filename

maybe this is an better/easier solution

Thanks

Rick

Re: awk - last minus one

am 18.12.2007 17:52:04 von Christian Gollwitzer

rickm@galaxy.nsc.com schrieb:
> awk -F / '/DEFINE/ { print $1 "./"$NF }' filename prints out
> the pieces of a string but I now need to print the last field and the
> one before it. There is no definate number fields so hardcoding to to
> pick up $8 $9 might not always work. Is there something like {$NF-1}
> or somethng?

$(NF-1)

or

n=NF-1
print $n

Christian

Re: awk - last minus one

am 18.12.2007 17:59:35 von Stephane CHAZELAS

On Tue, 18 Dec 2007 08:31:56 -0800 (PST), rickm@galaxy.nsc.com wrote:
> awk -F / '/DEFINE/ { print $1 "./"$NF }' filename prints out
> the pieces of a string but I now need to print the last field and the
> one before it. There is no definate number fields so hardcoding to to
> pick up $8 $9 might not always work. Is there something like {$NF-1}
> or somethng?
[...]

$(NF-1)

See your awk manual.

--
Stephane