need to parse the jil file into an excel file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need to parse the jil file into an excel file
# 1  
Old 10-18-2010
need to parse the jil file into an excel file

Hi I have the following as input
Code:
/* ----------------- 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
Code:
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.

Last edited by Scott; 10-18-2010 at 07:09 PM.. Reason: Please use code tags
# 2  
Old 10-18-2010
Hello,

Is this what you need?

Code:
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
# 3  
Old 10-18-2010
Code:
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[i]":";print"";for(i in A)printf "%s",A[i]":";print}' input

will give

Code:
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 Smilie

Last edited by ctsgnb; 10-19-2010 at 05:08 AM.. Reason: code fix machine|owner instead of machine.owner ...
# 4  
Old 10-18-2010
Hi Eagle,
thank you so much for the quick response , I have tried your code but I need this as my output

Code:
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

# 5  
Old 10-19-2010
I didnt get what you need first time; you can use ctsgnb's solution with OFS=|

Code:
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",M[i]OFS;print"";for(i in A)printf "%s",A[i]OFS;print}' OFS="|" infile

but i dont know either how to print the fields in requested order with this solution Smilie
# 6  
Old 10-19-2010
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 :
Code:
...
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"]}'

# 7  
Old 10-19-2010
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.
Code:
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]],(i<n)?";":RS}}
                             /insert_job/  {pr(); delete A}
                                           {for(i in F){if($0~"^"F[i])A[F[i]]=$2}}
                             END           {pr()}' infile

This produces:
Code:
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:
Code:
/* ----------------- 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.

Last edited by Scrutinizer; 10-19-2010 at 03:24 PM..
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to extract jil file details in a excelsheet

I am very new to shell scripting. I have a autosys jil file that looks like :-- /* ------------- JOB1 ------------------ */ insert_job: JOB1 job_type: b owner: cm@pelonmuck permission: gx,ge,wx,we,mx,me date_conditions: 1 days_of_week: mo,tu,we,th,fr,su start_time: "18:30"... (9 Replies)
Discussion started by: newbie_shell
9 Replies

2. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

3. Shell Programming and Scripting

Parse excel file with html on each cell

<DIV><P>Pré-condição aceder ao ecrã Home do MRS.</P></DIV><DIV><P>OK.</P></DIV><DIV><P>Seleccionar Pesquisa de Recepção Directa.</P></DIV><DIV><P>Confirmar que abriu ecrã de Recepção Directa.</P></DIV><DIV> (6 Replies)
Discussion started by: oliveiraum
6 Replies

4. Shell Programming and Scripting

awk to parse jil output

Hi , I have a jil file which i am trying to parse and print the job name and the condition corresponding to it. Below is the input file /* -------------------- testjob1 -------------------- */ insert_job: testjob1 job_type: c machine: unix owner: chidori condition: s(joba) and... (9 Replies)
Discussion started by: chidori
9 Replies

5. Shell Programming and Scripting

Perl script to Merge contents of 2 different excel files in a single excel file

All, I have an excel sheet Excel1.xls that has some entries. I have one more excel sheet Excel2.xls that has entries only in those cells which are blank in Excel1.xls These may be in different workbooks. They are totally independent made by 2 different users. I have placed them in a... (1 Reply)
Discussion started by: Anamika08
1 Replies

6. Shell Programming and Scripting

Writing excel file using perl : Excel file formatting changed

I am trying to create a program where user can input data in certain excel cells using user interface on internet....the programming is on perl and server is unix But when i parse data into excel the formatting of sheets is turned to default and all macro coding removed. What to do...Please... (7 Replies)
Discussion started by: mud_born
7 Replies

7. Shell Programming and Scripting

How to convert excel file to csv file or text file?

Hi all, I need to find a way to convert excel file into csv or a text file in linux command. The reason is I have hundreds of files to convert. Another complication is the I need to delete the first 5 lines of the excel file before conversion. so for instance input.xls description of... (6 Replies)
Discussion started by: johnkim0806
6 Replies

8. Shell Programming and Scripting

execute a .jil file

hello all, Could anyone please suggest me as to how could we execute a .jil file. Thanks in advance for your help. (4 Replies)
Discussion started by: OSD
4 Replies

9. UNIX for Advanced & Expert Users

execute a .jil file

Hi All, Could anyone suggest me as to how could we execute a .jil file. Thanks in advance. (1 Reply)
Discussion started by: OSD
1 Replies
Login or Register to Ask a Question