Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looking for lines... 1

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
0
0
PL

hallo,

input file (cron log file with lines) - mixed lines like:
root : CMD ( /home/den/proc400.ksh >/dev/null ) : PID ( 18940110 ) : Tue Nov 6 21:30:00 2012
root : CMD ( /home/den/clean.ksh full >/dev/null ) : PID ( 53412070 ) : Tue Nov 6 23:30:00 2012
Cron Job with pid: 18940110 Failed
Cron Job with pid: 18943456 Successful
Cron Job with pid: 19535560 Successful
Cron Job with pid: 53412070 Failed

and want to find all tasks which exited with error (Failed status).

What i wanted to do is:

for i in `grep "^Cron Job with pid" log|awk '{print $5}'|sort -u`
do
awk -vx=$a '$(NF-7) == x || $(NF-1) == x {print}' log|sed 'N;s/\n/,/'|grep Failed$
done

and then join every two lines and grep for Failed.

The problem is that
$(NF-7) == x || $(NF-1) == x
is doesn't do what I expect. I want it to find all lines having the PID number ($a) on position $(NF-1) or $(NF-7). is it possible knowing that some lines have less fields then 7?
 
Hi

Possible to misunderstood the requirement, as you posted no sample of expected output. This is based on the "join every two lines and grep for Failed" part :
Code:
awk '[blue]NF[/blue][teal]>[/teal][purple]10[/purple][teal]&&[/teal][navy]$(NF-9)[/navy][teal]==[/teal][green][i]"PID"[/i][/green][teal]{[/teal]p[teal][[/teal][navy]$(NF-7)[/navy][teal]]=[/teal][navy]$0[/navy][teal];[/teal][COLOR=chocolate]next[/color][teal]}[/teal][navy]$NF[/navy][teal]==[/teal][green][i]"Failed"[/i][/green][teal]{[/teal][COLOR=chocolate]print[/color] p[teal][[/teal][navy]$(NF-1)[/navy][teal]],[/teal][navy]$0[/navy][teal]}[/teal]' /input/file
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].

Feherke.
[link feherke.github.com/][/url]
 
you simply got it right ;-)

thank you!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top