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

Simplifying Several Lines of Output Into One Line 1

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
When I run a query for a job, it returns several lines of data, most of which I am not interested in. I would like to create a script to simplify the output below onto one line.

Date: 08/27/03 Object: TJOB Page 1

Jobset: aetrddly

Job: etrcheck

Jno: 0001 Qualifier: 2701

Station: gsc-fin Original Station: gsc-fin

Description: Asap: Tuesatwo: Script to check ETR Prod Batch

Run Status: COMPL Calendar: everyday Job PID: 00028607

Actual Node: gsc-fin

Actual Queue: a Cyclic Job: No Cycle Freqency: 60 Cycle Count: 0

Anycpu: No Autosel: Yes Backlog: Yes

Priority: 1 History: 0010 Hold: No Interruptible: No

Job Type: CPU Autostart: No Userenv: Yes

Abend Action: ABORT

Abort Count: Failcond: ( +0001 , +9999 )

Scheduled: 08/27/2003 00:00:51.00 Available: 08/27/2003 03:30:03.00
0 ( 24, 10) FDX

Early: 08/27/2003 03:30:00.00 Max. Time:

Must Start: Must Comp.:

Start: 08/27/2003 03:30:05.00 End: 08/27/2003 03:30:12.00

CPU Time: 00:00:01.52 Average Time: 00:00:07.00 High RC: 00000000

Users:

Cancel: Demand:

End: Hold:

Release: Start:

Update: lfl0 Submit:

Force:

###################################################

I tried using the command:

egrep '^ Start:|Jobset|Status|^ Job:'

Which gives me the data I want, but I'm not sure how I should go about using awk to create the columns I would like.

Jobset: aetrddly

Job: etrcheck

Run Status: COMPL Calendar: everyday Job PID: 00028607

Start: 08/27/2003 03:30:05.00 End: 08/27/2003 03:30:12.00

Ideally I would like the output to display as follows:

Jobset Job Start Date Start Time End Date End Time Status
============================================================
abcd a1 08/27/2003 08:45 08/27/2003 08:47 COMPL

Does anyone have any ideas as to how I can accomplish this? Any help would be greatly appreciated.

Thanks,

John
 
Try this. The egrep is not necessary.

awk -f jg.awk input-file

Code:
#   ------   jg.awk   ------
BEGIN {
  print "Jobset    Job    Start Date  Start Time  End Date   End Time  Status"
  print "============================================================"
}
/^ Start/{print jobset " " job " " $2 " " substr($3,1,5) " " $5 " " substr($6,1,5) " " status}
/Jobset/{jobset = $2}
/Status/{status = $3}
/^ Job:/{job = $2}

CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Thanks, CaKiwi. I just figured it out on my own. This is what I used:


BEGIN {OFS = "\t";printf ("%-10s %-10s %-12s %-12s %-12s %-12s %-10s","\nJobset","Job","Start Date", "Start Time", "End Date", "End Time", "Status");print "\n==
=============================================================================\n"
}
/Jobset:/{jobset = $2}
/ Job:/{job = $2}
/ Run Status:/{status = $3}
/ Start:/{sdate = $2; stime = $3; edate = $5; etime = $6}
/ Start:/{if (NF==6) printf ("%-10s %-10s %-12s %-12s %-12s %-12s %-10s\n", jobs
et, job, sdate, stime, edate, etime, status)}
 
Can someone please explain what is wrong with my script (see above)? I am getting:

Jobset Job Start Date Start Time End Date End Time Status

===============================================================================
aetrddly etrcheck 08/27/2003 03:30:05.00 08/27/2003 03:30:12.00 COMPL

aprmedly prmdeptc 08/27/2003 02:00:35.00 08/27/2003 02:00:39.00 COMPL

aprmedly prmetrex 08/27/2003 02:00:49.00 08/27/2003 02:11:30.00 COMPL

as my output. I'm not sure where the new lines are coming from in between the jobs and between the line of equals signs and the header.

John
 
I figured it out. There are additional spaces at the end of the lines in the input file, so when I was displaying the last field of a line, the spaces were being displayed as well. I changed the last space on the printf statements to say "%-1s\n" rather than "%-10s\n". The fields on the first line were also too large to display on one line, so I modified the spacing so that it fits.

John
 
I have come across another problem; if the job has not run yet, it does not have a start or end time, therefore when sdate, stime, edate, and etime are found, they are incorrect because the positional parameters are not correct. The statuses that this occurs for are:

OPHELD
START
WPRED
WSTART

Basically, if the status is not ABORT or COMPL, the positional parameters are not going to be correct. I know that there is the option of using an if statement, but I'm not sure if there is an option for an else. Any help on resolving this would be greatly appreciated.

Thanks,

John
 
I'm not sure exactly what you want, but this may get you started.

/Start:/{
if (status=="OPHELD" || status=="START" || ...) {
sdate = $3
...
}
else {
sdate = $3
...
}
printf ("%-10s ...
}

CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Thanks, CaKiwi!! I wasn't sure what the syntax was for the if/else with awk. With your help, I got everything working the way I want it.

Thanks,

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top