[plug] Using the "cut" command on fields seperated with variable number of spaces

Leon Brooks leon at brooks.fdns.net
Thu Jan 30 09:32:42 WST 2003


On Thursday 30 January 2003 08:59 am, David Buddrige wrote:
> ps -aux

> USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
> root         1  0.0  0.0  1368   76 ?        S     2002   0:04 init [5]
> root         2  0.0  0.0     0    0 ?        SW    2002   0:00 [keventd]
> root         3  0.0  0.0     0    0 ?        SW    2002   0:00 [kapm-idled]
> root         4  0.0  0.0     0    0 ?        SW    2002   5:01 [kswapd]
> [etc]

> Does anyone know how to extract (for example) the PID
> field from this kind of output?

    ps -aux | \
      gawk '$2 != "PID" { print $2 }'

To only do fred's processes:

    ps -aux | \
      gawk '/^fred / { print $2 }'

And yes, there will be at least 30 ways of doing this in PERL... (-:

Cheers; Leon



More information about the plug mailing list