awk question

Discussion in 'Programming/Scripts' started by tera7, Aug 8, 2008.

  1. tera7

    tera7 New Member

    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.
  2. burschik

    burschik New Member

    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 }'

Share This Page