need to parse the jil file into an excel file

Hi I have the following as input

/* ----------------- backupJIL ----------------- */ 

insert_job: backupJIL job_type: c 
command: autorep -J ALL -q > /home/autosys/...p/autosys_jil_bk
machine: machine
owner: autosys@machine
permission: gx,ge,wx,we
date_conditions: 1
days_of_week: tu,we,th,fr,sa
start_times: "17:00"
description: "Daily backup of job definitions"
std_out_file: /tmp/autosys_jil_backup.out
std_err_file: /tmp/autosys_jil_backup.err
alarm_if_fail: 1
/* ----------------- BC_mount ----------------- */ 

insert_job: BC_mount job_type: c 
box_name: SAN_test_refresh_box
command: /sysadm/xp/bin/mountprodbc.sh
machine: b_dexter
owner: autosys@/* ----------------- BC_mount ----------------- */ 

insert_job: BC_mount job_type: c 
box_name: S..fresh_box
command: /sysadm/xp/bin..odbc.sh
machine: machine
owner: autosys@machine
permission: gx,wx
condition: success(Check_BC_Status)
description: "Mount the BCs on machine"
std_out_file: >/var/tmp/mountprodbc.log
std_err_file: >/var/tmp/mountprodbc.err
alarm_if_fail: 1

would like this as output

insert_job,box_name,command,machine.owner,permission,condition,description,std_out_file,std_err_file ,alarm_if_fail

and their respective values in the next line. how to do this using sed/awk/ksh.

Hello,

Is this what you need?

nawk -F\: '{gsub("^[ ]","",$2)} /insert_job/||/box_name/||/command/||/machine.owner/ {print $1"\n"$2}' OFS=":" inputfile

here I didnt put all the strings that you search in input file (i placed only first four), you can insert all of them into command

regards

awk -F": " '$1~/(insert_job|box_name|command|machine|owner|permission|condition|description|std_out_file|std_err_file|alarm_if_fail)/ {M[$1]=$1;A[$1]=$2} END {for(i in M)printf "%s",M":";print"";for(i in A)printf "%s",A":";print}' input

will give

date_conditions:alarm_if_fail:insert_job:std_err_file:permission:condition:std_out_file:description:box_name:command:
1:1:BC_mount job_type:>/var/tmp/mountprodbc.err:gx,wx:success(Check_BC_Status):>/var/tmp/mountprodbc.log:"Mount the BCs on machine":S..fresh_box:/sysadm/xp/bin..odbc.sh:

couldn't figure out how to get the field in the requested order ...
don't know if it could make sens to use M[3],M[2]... instead of loop "for".

We need Scrutinizer spirit :rolleyes:

Hi Eagle,
thank you so much for the quick response , I have tried your code but I need this as my output

insert_job|job_type|box_name|command|machine|owner|permission|date_conditions|days_of_week|start_times|condition|description|std_out_file|std_err_file|alarm_if_fail
backupJIL|c||autorep -J ALL -q > /home/autosys/...p/autosys_jil_bk|machine|autosys@machine|gx,ge,wx,we|1|tu,we,th,fr,sa|"17:00"||"Daily backup of job definitions"|/tmp/autosys_jil_backup.out|/tmp/autosys_jil_backup.err| 1
BC_mount|c|SAN_test_refresh_box|/sysadm/xp/bin/mountprodbc.sh|b_dexter|autosys@|||||||||||
BC_mount|c |S..fresh_box|/sysadm/xp/bin..odbc.sh|machine|autosys@machine|gx,wx||||success(Check_BC_Status)|"Mount the BCs on machine"|>/var/tmp/mountprodbc.log|>/var/tmp/mountprodbc.err|1

I didnt get what you need first time; you can use ctsgnb's solution with OFS=|

nawk -F": " '$1~/(insert_job|job_type|box_name|command|machine|owner|permission|date_conditions|days_of_week|start_times|condition|description|std_out_file|std_err_file|alarm_if_fail)/ {M[$1]=$1;A[$1]=$2} END {for(i in M)printf "%s",MOFS;print"";for(i in A)printf "%s",AOFS;print}' OFS="|" infile

but i dont know either how to print the fields in requested order with this solution :frowning:

Could pipe it into another awk that would re-order the column like
$3,$9,$1,$10,$5,$6,$8,$7,$4,$2... or something like that, but this would not be optimal.

I guess we should directly refer the expected element of array instead of doing a "for" loop to display.I just don't know whether it can handle such syntax :

...
printf "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n",M["insert_job"],M["job_type"],M["box_name"],M["command"],M["machine"],M["owner"],M["permission"],M["date_conditions"],M["days_of_week"],M["start_times"],M["condition"],M["description"],M["std_out_file"],M["std_err_file"],M["alarm_if_fail"];printf "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n",A["insert_job"],A["job_type"],A["box_name"],A["command"],A["machine"],A["owner"],A["permission"],A["date_conditions"],A["days_of_week"],A["start_times"],A["condition"],A["description"],A["std_out_file"],A["std_err_file"],A["alarm_if_fail"]}'

We can not use a comma as a output field separator since some of the fields contain commas. I used a semicolon instead, which is fine for importing into Excel.

awk -F ' *[[:alnum:]_]*: *' 'BEGIN         {h="insert_job;box_name;command;owner;permission;condition;description;std_out_file;std_err_file;alarm_if_fail"; 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<n)?";":RS}}
                             /insert_job/  {pr(); delete A}
                                           {for(i in F){if($0~"^"F)A[F]=$2}}
                             END           {pr()}' infile

This produces:

insert_job;box_name;command;owner;permission;condition;description;std_out_file;std_err_file;alarm_if_fail
backupJIL;;autorep -J ALL -q > /home/autosys/...p/autosys_jil_bk;autosys@machine;gx,ge,wx,we;;"Daily backup of job definitions";/tmp/autosys_jil_backup.out;/tmp/autosys_jil_backup.err;1
BC_mount;S..fresh_box;/sysadm/xp/bin..odbc.sh;autosys@machine;gx,wx;success(Check_BC_Status);"Mount the BCs on machine";>/var/tmp/mountprodbc.log;>/var/tmp/mountprodbc.err;1

What made it a bit more complex is that not all of the fields are present in every record.
The input file seemed to be a bit crooked, I used this as a basis, hope that is OK:

/* ----------------- backupJIL ----------------- */

insert_job: backupJIL job_type: c
command: autorep -J ALL -q > /home/autosys/...p/autosys_jil_bk
machine: machine
owner: autosys@machine
permission: gx,ge,wx,we
date_conditions: 1
days_of_week: tu,we,th,fr,sa
start_times: "17:00"
description: "Daily backup of job definitions"
std_out_file: /tmp/autosys_jil_backup.out
std_err_file: /tmp/autosys_jil_backup.err
alarm_if_fail: 1
/* ----------------- BC_mount ----------------- */

insert_job: BC_mount job_type: c
box_name: S..fresh_box
command: /sysadm/xp/bin..odbc.sh
machine: machine
owner: autosys@machine
permission: gx,wx
condition: success(Check_BC_Status)
description: "Mount the BCs on machine"
std_out_file: >/var/tmp/mountprodbc.log
std_err_file: >/var/tmp/mountprodbc.err
alarm_if_fail: 1

S.

1 Like

@ Scrutinizer,
your solution is amazing , it works perfect for me.Thanks a ton.