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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting from multiple lines of an input file 1

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
I have created the following awk script which I use to display the completion time of jobs:

Code:
#-----jobchk.awk-----
#Used to print completed jobs from the syslog.
#
BEGIN {print "\n";printf ("%-10s %-10s %-11s %11s %10s %8s\n","Jobset","Job","End Date","End Time", "Status", "  RC");print "==============================================================================="}
/01 Completed/{jobset = $7; job = $8; edate = $1; edated = $2; status = $11; etime = $3 ; rc = $15; if (NF>=13) printf ("%-10s %-10s %-3s %-10s %-12s %-12s %-6s\n", jobset, job, edate, edated, etime, status, rc)}
END{print ""}
This works fine for displaying the completion time using input in the format shown below.

Sep 22 10:15:44 server123 root: .CASH_I_0069 jobset1 job22 0001 2201 Started at 10.15.44 at node server123, Pid = 00019551
Sep 22 10:20:44 serverB root: .CASH_I_0069 jobset33 job1 0001 2201 Started at 10.20.44 at node sysmgt, Pid = 00019551
Sep 22 10:21:03 serverB root: .CASH_I_0054 jobset33 job1 0001 2201 Completed at 10.21.03, code: 00000000 at node serverB, Pid = 00019551
Sep 22 10:28:42 server123 root: .CASH_I_0054 jobset1 job22 0001 2201 Completed at 10.28.42, code: 00000000 at node server123, Pid = 00019385

The resulting output of the awk script is:

Jobset Job End Date End Time Status RC
===============================================================================
jobset33 job1 Sep 22 10:21:03 Completed 00000000
jobset1 job22 Sep 22 10:28:42 Completed 00000000

What I would like to accomplish is displaying both the start and end times for each job using 1 awk script.

I would like to capture fields 1, 2, 3, 7, and 8 from the "Started" lines and fields 1, 2, 3, 11, and 15 from the corresponding "Completed" line.

The final output should be:

Jobset Job Start Date Start Time End Date End Time Status RC
===============================================================================
jobset33 job1 Sep 22 10:20:44 Sep 22 10:21:03 Completed 00000000
jobset1 job22 Sep 22 10:15:44 Sep 22 10:28:42 Completed 00000000

Any help would be greatly appreciated.

Thanks,

John
 
A starting point:
/01 Started/{i=$7","$8;m=$1;d=$2;t=$3}
/01 Completed/{i=$7","$8;print $7,$8,m,d,t,$1,$2,$3,$11,$15}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks, PH!! That works great!! With a little bit of formatting, I should be all set.

Thanks,

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top