how would you solve this problem?

I have a file process.txt

I wanted to just grab data in "process" column.

Name process process_id status

Adminserver adminserver 22669 Running
Browser Engine browserengine 22846 Running
Cache Manager cachemanager 22740 Running
CG Log Dispatcher cglogdispatcher 22905 Running
Clarity clarity_webcluster 22950 Running
Query Completion Server completionserver 22782 Running

So I did this, but the problem is that I have to keep on piping to perl to get rid of spaces as long as there are in "Name" column so that awk can know what is in $2.

$ cat stuff | perl -pe 's,\ ,,' | perl -pe 's,\ ,,' | awk '{print $2}'
adminserver
browserengine
cachemanager
cglogdispatcher
clarity_webcluster
completionserver

How would you resolve this?
:o

# cat shit | awk '{print $(NF-1)}'

UUOC.:confused:
Take a look at (g)awks match function.

From the example you give for file process.txt, it has either 4,5 or 6 fields,
dependant on how many spaces are in the "Name" field.

awk ' BEGIN { FS=" " } NF == "4" { print $2 } NF == "5" { print $3  } NF == "6" { print $4  }' process.txt

I think redhat's solution would work if you only:

  1. Change shit with process.txt
  2. Change NF-1 with NF-2

:wink:

... and lose the Useless Use of Cat, for a full ten points. (^;

Sorry, I was on a power trip there, so I let the cat out of the bag :wink:

Hi

Thanks for all. My big linux book did not really cover this subtract trick of awk.