Need to extract jil file details in a excelsheet


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to extract jil file details in a excelsheet
# 1  
Old 02-28-2017
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 :--
Code:
/* ------------- 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"
box_success: s(SOME_JOB1) and s(SOME_JOB2) and s(SOME_JOB3)
box_failure: (f(SOME_JOB1) or f(SOME_JOB2)) & f(SOME_JOB3)
description: "pull files"
max_run_alarm: 15
alarm_if_fail: 1
timezone: US/Eastern


/* ------------- JOB2 ------------------ */

insert_job: JOB2    job_type:  c
box_name: SOME_BOX_NAME
command: /usr/bin/run /usr/cache/START_JOB
machine: machine@conti.com
owner:     cm@pelonmuck        
permission: gx,ge,wx,we,mx,me
days_of_week: sa,su
description: "pull all files"
max_run_alarm: 15
alarm_if_fail: 1
timezone: GMT

I need to create a shell script to get the output in a excelsheet/csv format like below:-

Code:
insert_job,machine,date_conditions,days_of_week,start_time,timezone,description,command,alarm_if_fail
JOB1,,1,mo,tu,we,th,fr,su,"18:30",US/Eastern,"pull files",,1
JOB2,machine@conti.com,,sa,su,,GMT,"pull all files",/usr/bin/run /usr/cache/START_JOB,1

Could you all pls help me to build this.


Moderator's Comments:
Mod Comment Please use CODE tags correctly as required by forum rules!

Last edited by RudiC; 02-28-2017 at 02:27 PM.. Reason: Changed ICODE to CODE tags.
# 2  
Old 02-28-2017
Any attempts / ideas / thoughts from your side?
# 3  
Old 02-28-2017
Hi RudiC, Yeah , I guess we need to parse the file first and look out for those compulsory columns name in the output and then pullout the values next to that ....
# 4  
Old 02-28-2017
What have you tried?
# 5  
Old 03-02-2017
I have reached quite close thanks to a already existing thread
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 > outfile.csv

The issue with above code is, it gives me the output as below:-
Code:
insert_job,machine,date_conditions,days_of_week,start_time,timezone,description,command,alarm_if_fail
JOB1;;1,mo,tu,we,th,fr,su;";US/Eastern;"pull files";;1
JOB2;machine@conti.com;;sa,su;;GMT;"pull all files";/usr/bin/run /usr/cache/START_JOB;1

Its not able to print the start_time in first row, which should be "18:30"
Any idea, how do we print the start_time which is in int format

Last edited by newbie_shell; 03-02-2017 at 09:24 AM.. Reason: Completed the query
# 6  
Old 03-02-2017
Try
Code:
awk -F: '
NR==1           {HD = "insert_job,machine,date_conditions,days_of_week,start_time,timezone,description,command,alarm_if_fail"
                 for (HDCnt=i=split(HD, HDArr, OFS); i>0; i--) SRCH[HDArr[i]] 
                 print HD
                }

function PRT()  {for (i=1; i<=HDCnt; i++)       {printf "%s%s", RES[HDArr[i]], i<HDCnt?OFS:ORS
                                                }
                 split ("", RES)
                }

/--- JOB/       {if (PR) PRT()
                 PR=1
                }

$1 in SRCH      {T = $1
                 sub ($1 FS " *", "")
                 sub (/  +.*$/, "")
                 RES[T] = $0
                }

END             {PRT()
                }
' OFS=","  file
insert_job,machine,date_conditions,days_of_week,start_time,timezone,description,command,alarm_if_fail
JOB1,,1,mo,tu,we,th,fr,su,"18:30",US/Eastern,"pull files",,1
JOB2,machine@conti.com,,sa,su,,GMT,"pull all files",/usr/bin/run /usr/cache/START_JOB,1

This User Gave Thanks to RudiC For This Post:
# 7  
Old 03-02-2017
Thanks, I have one final hurdle.

The script you gave on top works like magic but only where the jil details does not have leading spaces.
For example for a jil file containing below jil detail:-
Code:
  /* ------------- 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"
  box_success: s(SOME_JOB1) and s(SOME_JOB2) and s(SOME_JOB3)
  box_failure: (f(SOME_JOB1) or f(SOME_JOB2)) & f(SOME_JOB3)
  description: "pull files"
  max_run_alarm: 15
  alarm_if_fail: 1
  timezone: US/Eastern

the output will not have anything other than the header because of leading spaces, my infile has leading spaces in multiple places(not more than 2 or 3 spaces) and those details are just skipped by the script.
Can you please help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract sentence and its details from a text file based on another file of sentences

Hi I have two text files. The first file is TEXTFILEONE.txt as given below: <Text Text_ID="10155645315851111_10155645333076543" From="460350337461111" Created="2011-03-16T17:05:37+0000" use_count="123">This is the first text</Text> <Text Text_ID="10155645315851111_10155645317023456"... (7 Replies)
Discussion started by: my_Perl
7 Replies

2. Shell Programming and Scripting

Perl : corrupted excelsheet while trying to open

Hi folks, I am trying to send the mail with spreadsheet attachment in perl.I am able to send the mail with xlsx attachment as well but not able to open the xlsx sheet.While opening the sheet I am receiving the corrupted message. Below is the code. use MIME::Lite; use Net::SMTP; ###... (1 Reply)
Discussion started by: scriptscript
1 Replies

3. UNIX for Dummies Questions & Answers

at -l doesnt give details of the scheduled job. How to get the details?

I have scheduled couple of shell scripts to run using 'at' command. The o/p of at -l is: $ at -l 1320904800.a Thu Nov 10 01:00:00 2011 1320894000.a Wed Nov 9 22:00:00 2011 1320876000.a Wed Nov 9 17:00:00 2011 $ uname -a SunOS dc2prcrptetl2 5.9 Generic_122300-54 sun4u sparc... (2 Replies)
Discussion started by: superparticle
2 Replies

4. Shell Programming and Scripting

Extract details from XML file

Hi , I have one xml file contains more than 60 lines. I need to extract some details from the file and store it in new file.Not the whole file Please find the xml file below: <?xml version="1.0" encoding="UTF-8"?> <DeploymentDescriptors xmlns="http://www.tibco.com/xmlns/dd"> ... (6 Replies)
Discussion started by: ckchelladurai
6 Replies

5. Shell Programming and Scripting

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:... (7 Replies)
Discussion started by: ramky79
7 Replies

6. Shell Programming and Scripting

Contents and details extract problem asking...

Input: length align type 5453 8666 + length align portion 5453 8666 + length align range 5453 5616 + length align name 5453 6121 + length align age 5617 6121 + length align name 7214 7404 + length ... (11 Replies)
Discussion started by: patrick87
11 Replies

7. Shell Programming and Scripting

Help with excelsheet generation

Hi All, i have around 50 queries in sybase. We have a requirement where we need to write a unix script, which execute the query one by one & generate the excel sheet & send it to user. I have completed half of the part, where i am executing query one by one & putting the result into a .txt... (4 Replies)
Discussion started by: Amit.Sagpariya
4 Replies

8. Shell Programming and Scripting

i want to extract details for particular file

Hi i have following file uuid ( RO) : 62701790-60da-dd9a-669d-a563aac1c435 host-uuid ( RO): 5f3f668d-a7c7-4e5f-a4a6-6e90fafb50ed sr-uuid ( RO): 62103d07-e0aa-acf3-2d9f-414ad3377bd0 device-config (MRO): location: /dev/xapi/block ... (6 Replies)
Discussion started by: bp_vardhaman
6 Replies

9. 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

10. 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