PDA

View Full Version : awk question


tera7
8th August 2008, 02:18
Hello why this command :


uptime|awk x=NF-2 i=NF-1 y=NF'{print $x,$i,$y }'


prints that :


00:16:33 up 1 day, 8:29, 1 user, load average: 0.44, 0.18, 0.11

i expect something like this:

0.44, 0.18, 0.11

i do not need this i am just asking.

burschik
8th August 2008, 08:50
I'm surprised it works at all. However, you can not use NF before it has been defined. Therefore, you need to do something like this:

uptime|awk '{x=NF-2; i=NF-1; y=NF; print $x,$i,$y }'