I am newish to awk and I am trying to parse/pivot out a JIL to be consumed by SAS or Excel

178 Views Asked by At

I am trying to parse all 300+ Autosys jobs I am in charge of managing and would like be able to parse a large 300+ autosys job JIL file to automate some reporting.

I am severely limited on what software I am allowed to use. I recently found this awk script. I tried a SAS solution but that was only getting me 1/2 of the data. A Perl script could work, but I am not well versed in perl. Awk has seem the easier for me to understand and utilize

awk -F ' *[[:alnum:]_]*: *' 'BEGIN         {h="insert_job;box_name;machine;command;owner;permission;date_conditions;days_of_week;run_calendar;start_times;condition;description;std_out_file;std_err_file;alarm_if_fail;profile;priority;alarm_if_terminated;timezone;group;application;resources;"; print h; n=split(h,F,/;/)}
                             function pr() {if(F[1] in A) {for(i=1;i<=n;i++)printf "%s%s",A[F[i]],(i<n)?";":RS}}
                             /insert_job/  {pr(); delete A}
                                           {for(i in F){if($0~"^"F[i])A[F[i]]=$2}}
                             END           {pr()}' /foo/bar/all.jil > /foo/bar/outfile2.txt

Sample Jil (this is the input):

/* ----------------- somejob ----------------- */ 

insert_job: somejob   job_type: CMD 
command: SAS ${AUTO_ROOT}/pgms/somejob.sas
machine: someserver.com
owner: user1
permission: gx,wx
date_conditions: 1
run_calendar: 1st_bus_dom
start_times: "07:00"
condition: s(someotherjob)
description: "Send email notification."
std_out_file: "${AUTO_JOB_LOG}.out"
std_err_file: "${AUTO_JOB_LOG}.err"
alarm_if_fail: 1
profile: "/foo/bar/etc/app1"
alarm_if_terminated: 1
timezone: CST6CDT
group: grp1
application: app1
resources: (someresource,QUANTITY=2,FREE=A)

/* ----------------- somejob2 ----------------- */ 

insert_job: somejob2   job_type: CMD 
command: SAS ${AUTO_ROOT}/pgms/somejob2.sas
machine: someserver.com
owner: user1
permission: gx,wx
date_conditions: 1
run_calendar: 1st_bus_dom
start_times: "07:00"
condition: s(someotherjob)
description: "Send email notification."
std_out_file: "${AUTO_JOB_LOG}.out"
std_err_file: "${AUTO_JOB_LOG}.err"
alarm_if_fail: 1
profile: "/foo/bar/etc/app1"
alarm_if_terminated: 1
timezone: CST6CDT
group: grp1
application: app1
resources: (someresource,QUANTITY=2,FREE=A)

Sample output

insert_job;box_name;machine;command;owner;permission;date_conditions;days_of_week;run_calendar;start_times;condition;description;std_out_file;std_err_file;alarm_if_fail;profile;priority;alarm_if_terminated;timezone;group;application;resources;
somejob;;someserver.com;SAS ${AUTO_ROOT}/pgms/somejob.sas;user1;gx,wx;1;;1st_bus_dom;"07:00";s(someotherjob);"Send email notification.";"${AUTO_JOB_LOG}.out";"${AUTO_JOB_LOG}.err";1;"/foo/bar/etc/app1";;1;CST6CDT;grp1;app1;(someresource,QUANTITY=2,FREE=A);
somejob2;;someserver.com;SAS ${AUTO_ROOT}/pgms/somejob2.sas;user1;gx,wx;1;;1st_bus_dom;"07:00";s(someotherjob);"Send email notification.";"${AUTO_JOB_LOG}.out";"${AUTO_JOB_LOG}.err";1;"/foo/bar/etc/app1";;1;CST6CDT;grp1;app1;(someresource,QUANTITY=2,FREE=A);

I would like to figure out why the start_times is not being properly parsed into the outfile2.txt. I am only receiving the first " from that line.

EDIT: It looks like the RegExpression part of the printf is not reading and printing the numeric characters. I am not really sure how to fix this now.

EDIT 2: Looks the like issue entails that the "start_times" content. I have been tryng to brush myself up on how to fix that, but I have no luck. Current output just adds the first " we it should output the entire line for the start_times: "07:00"

Current awk I am using returns something like this below:

somejob;;;;user1;gx,wx;1;;1st_bus_dom;";;

I am wanting this

somejob;;;;user1;gx,wx;1;;1st_bus_dom;"7:00";;
0

There are 0 best solutions below