1847248 Members
2416 Online
110263 Solutions
New Discussion

Re: awk help

 
SOLVED
Go to solution
Kevin Wright
Honored Contributor

awk help

I am writing a script to kill background jobs using jobs -l and using awk to get the process id's..however, the first two lines have a + and a - in the second field, so if I awk '{print $3}', I get the first two PID's and then for the last two I get 'Running'..anyone know of anyway around this?
[4] + 18982 Running
[3] - 18981 Running
[2] 18980 Running
[1] 18979 Running
2 REPLIES 2
John Poff
Honored Contributor
Solution

Re: awk help

Hello,

I played with awk and I got this line to work:

awk '{i=NF-1; print $i}'


The NF variable is the number of fields on the input line. This sets the variable 'i' to one less than NF and prints it.

JP

Kevin Wright
Honored Contributor

Re: awk help

Thanks for the reply, I just got this to work
awk '{print $(NF -3)}'
because NF is actually the command field in the jobs output.