awk - last minus one
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
On Tue, 18 Dec 2007 08:31:56 -0800 (PST), rickm [at] 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
Re: awk - last minus one
rickm [at] 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