Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Need to extract jil file details in a excelsheet

Shell Programming and Scripting


Tags
jil, parsing, shell script

Closed    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 03-02-2017   -   Original Discussion by newbie_shell
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 22 April 2018, 1:04 PM EDT
Location: Aachen, Germany
Posts: 12,505
Thanks: 401
Thanked 3,877 Times in 3,564 Posts
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
                }

                {sub ("^  *", _)
                }

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

END             {PRT()
                }
' OFS=","  file

Please be aware that the structure of the line containing insert_job differs from the data in post#1 (<TAB> separated, not spaces), so the splitting off of the job_type doesn't work any more.
Sponsored Links
    #9  
Old Unix and Linux 03-03-2017   -   Original Discussion by newbie_shell
andy391791's Unix or Linux Image
andy391791 andy391791 is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 30 March 2017, 7:48 AM EDT
Posts: 35
Thanks: 13
Thanked 8 Times in 8 Posts
Hi Rudi, would it be possible for you to explain how this script works? Im still learning awk and theres a lot i dont understand in this script?
Many thanks
Sponsored Links
    #10  
Old Unix and Linux 03-03-2017   -   Original Discussion by newbie_shell
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 22 April 2018, 1:04 PM EDT
Location: Aachen, Germany
Posts: 12,505
Thanks: 401
Thanked 3,877 Times in 3,564 Posts
That proposal is only a slight adaption of the script you posted as your attempt. How about you try to explain it here, and we jump in on the gaps that you can't cover?
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extract sentence and its details from a text file based on another file of sentences my_Perl Shell Programming and Scripting 7 10-18-2015 05:38 PM
Extract details from XML file ckchelladurai Shell Programming and Scripting 6 07-29-2011 09:01 AM
Contents and details extract problem asking... patrick87 Shell Programming and Scripting 11 03-31-2010 09:19 PM
Help with excelsheet generation Amit.Sagpariya Shell Programming and Scripting 4 03-04-2009 09:17 AM
i want to extract details for particular file bp_vardhaman Shell Programming and Scripting 6 08-21-2008 10:55 AM



All times are GMT -4. The time now is 02:08 PM.