don't print last field
Phil Meyer
pmeyer at themeyerfarm.com
Mon Nov 10 21:43:59 UTC 2008
adrian kok wrote:
> Hi
>
> how can I only get the previous field but not last
> field from awk?
>
> but I can't use print $1....$2
>
> as there are different fields in different line
>
> thank you
>
> Send instant messages to your online friends http://uk.messenger.yahoo.com
>
>
As another posted, NF is what you want to play with. Here is an example:
ls -l | awk '{ num = NF - 2 ; print $num }'
Please note that awk can use both types of shell variable notations:
With or without the dollar sign on an assignment.
So assign a value based upon NF WITHOUT the dollar sign, and print the
value WITH a dollar sign.
Hope this helps.
Have Fun!
More information about the fedora-list
mailing list