awk to parse jil output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to parse jil output
# 1  
Old 12-03-2013
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

Code:
/* -------------------- testjob1 -------------------- */

insert_job: testjob1   job_type: c
machine: unix
owner: chidori
condition: s(joba) and s(jobc)
std_out_file: /export/home/chidori/test.out
std_err_file: /export/home/chidori/test.err

   /* -------------------- testjob2 -------------------- */

   insert_job: testjob2   job_type: c
   machine: unix
   owner: chidori
   condition: s(jobc)
   std_out_file: /export/home/chidori/test.out
   std_err_file: /export/home/chidori/test.err

  /* -------------------- testjob3 -------------------- */

insert_job: testjob3   job_type: c
machine: unix
owner: chidori
condition: s(joba) or s(jobc)
std_out_file: /export/home/chidori/test.out
std_err_file: /export/home/chidori/test.err


I have figured out this one liner to do this


awk '{sub(/^ */,"");if($0~/^$){a++};if($0~/^\//){printf "%s = ", $3};if($0~/^condition:/){sub("condition: ","");print}}' sample.jil

Condition:
At times a job might not have any condition in them , in that case the script should print as "No_Condition".

I am not able to figure out how to write the code that can check if condition string does not exist then print "No_Condition". Can someone please help me out.

Also i was thinking if we can consider from the line that begins with /* to the line before the next /* as one record and do some processing. But was not sure how to implement the same.
# 2  
Old 12-03-2013
Here is one way of doing it:
Code:
awk '
        /^[ ]*\/\*/ {
                if ( NR > 1 && !(f) )
                        print "No_Condition"
                f = 0
                printf ( "%s = ", $3 )
        }
        /condition:/ {
                f = 1
                sub ( /[ ]*condition:[ ]*/, X)
                print
        }
        END {
                if (!(f))
                        print "No_Condition"
        }
' sample.jil

This User Gave Thanks to Yoda For This Post:
# 3  
Old 12-03-2013
That worked!!

Can you please explain the logic around here
# 4  
Old 12-03-2013
This is a starting point and needs some refinement, but it can guide you to a better solution:
Code:
awk 'NF==1 {next} {for (i=1; i<=NF; i++) if ($i ~ /insert|condition| or|and/) print $(i+1)} !/condition/ {print "no_condition"}' RS=-+ file
testjob1
s(joba)
s(jobc)
testjob2
s(jobc)
testjob3
no_condition

(I removed the condition line from the third record)
# 5  
Old 12-03-2013
If am using a flag variable: f and it is set when awk finds pattern /condition:/

So when awk finds next pattern /^[ ]*\/\*/ for job name, I am checking if this flag variable is set or not.

If not set, then print No_Condition. Same is done in the END rule to cover last job name.
# 6  
Old 12-03-2013
Thanks, Whats up with NR > 1 why we are going for a record greater than 1

---------- Post updated at 12:28 PM ---------- Previous update was at 12:26 PM ----------

Quote:
Originally Posted by RudiC
This is a starting point and needs some refinement, but it can guide you to a better solution:
Code:
awk 'NF==1 {next} {for (i=1; i<=NF; i++) if ($i ~ /insert|condition| or|and/) print $(i+1)} !/condition/ {print "no_condition"}' RS=-+ file
testjob1
s(joba)
s(jobc)
testjob2
s(jobc)
testjob3
no_condition

(I removed the condition line from the third record)
Hey RudiC, Can you please explain the record seperator we use here. RS=-+
# 7  
Old 12-03-2013
I used NR > 1 because for first job name, the flag variable: f is going to be initially 0 or null anyway.

So I don't want to check if flag is set or not for first job, but for all subsequent jobs.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Parse output and then compare column wise with awk

Hello, I am trying to write a script to parse the output of data and then alert based on certain conditions This is the output of my script (STRING) Name = Joe (FLOAT64) BMI = 34 (FLOAT64) Weight = 156 (STRING) Name = Sam (FLOAT64) BMI = 32 (FLOAT64) Weight = 180 and so on it repeats... (4 Replies)
Discussion started by: sidnow
4 Replies

2. Shell Programming and Scripting

How to parse this file using awk and output in CSV format?

My source file looks like this: Cust-Number = "101" Cust-Name="Joe" Cust-Town="London" Cust-hobby="tennis" Cust-purchase="200" Cust-Number = "102" Cust-Name="Mary" Cust-Town="Newyork" Cust-hobby="reading" Cust-purchase="125" Now I want to parse this file (leaving out hobby) and... (10 Replies)
Discussion started by: Balav
10 Replies

3. Shell Programming and Scripting

awk to parse df output

Output of the below code includes unmatched date.Please correct it df -k|awk '$4>50 {print $1, "\t"$4,"\t" $7}' It gives output less than 50% also. (5 Replies)
Discussion started by: vinil
5 Replies

4. Shell Programming and Scripting

awk - Parsing Autosys JIL

I'm trying to modify the script given in post 7 of the following thread: 146564-need-parse-jil-file-into-excel-file.html. (Sorry, can't post the URL as I don't have enough posts.) The original script is as follows: awk -F ' *_]*: *' 'BEGIN ... (9 Replies)
Discussion started by: GnuScripter
9 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

Parse snoop output

Hi all, Is it possible to create an script that parse an snoop output similar to the example above ? Each line is ended by "$" (set list in vi). as a result, I would like to print the output in only one line. can someone give me some tip ? Thanks a lot .:) l version="1.0" ... (5 Replies)
Discussion started by: robdcb
5 Replies

7. Shell Programming and Scripting

Parse file using awk and work in awk output

hi guys, i want to parse a file using public function, the file contain raw data in the below format i want to get the output like this to load it to Oracle DB MARWA1,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 MARWA2,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 this the file raw format: Number of... (6 Replies)
Discussion started by: dagigg
6 Replies

8. Shell Programming and Scripting

cat file and parse output

Hello, I'm new to shell scripting and did a search on the forum to what I want to do but couldn't find anything. I have about 9 routers that outputs to 1 syslog file daily named cisco.year.mo.date.log ex: cisco.2009.05.11.log My goal is to make a parsing script that cats today's syslog... (2 Replies)
Discussion started by: jjrambar
2 Replies

9. Shell Programming and Scripting

To parse through the file and print output using awk or sed script

suppose if u have a file like that Hen ABCCSGSGSGJJJJK 15 Cock ABCCSGGGSGIJJJL 15 * * * * * * : * * * . * * * : Hen CFCDFCSDFCDERTF 30 Cock CHCDFCSDHCDEGFI 30 * . * * * * * * * : * * :* : : . The output shud be where there is : and . It shud... (4 Replies)
Discussion started by: cdfd123
4 Replies

10. UNIX for Dummies Questions & Answers

parse through one text file and output many

Hi, everyone The input file pattern is like below: Begin Object1 txt1 end ; Begin Object2 txt2 end ; ... (14 Replies)
Discussion started by: sophiadun
14 Replies
Login or Register to Ask a Question