Help with awk/sed

Hi,
I am a newbie in UNIX and need a help here .
I have a file from which I need to extract data based on a certain search pattern.
E.g, consider the below file

/* ----------- IB_QEF_INF_1244_DMFullBox_job------------*/
##########some data##########
##########some data##########

/* ----------- IB_QEF_INF_1244_DMGRPFPMSIn_Box -----------*/

##########some data##########
##########some data##########
/* ------------- IB_QEF_INF_1244_DMGRPFPMS_Box ---------- */
##########some data##########
##########some data##########

Now, I need to extract the data between the patterns /* ----------- IB_QEF_INF_1244_DMFullBox_job------------/
and /
----------- IB_QEF_INF_1244_DMGRPFPMSIn_Box -----------*/.

Like this I have numberous different patterns starting with the same word IB_QEF_INF_1244*

Hope I am clear with the requirement.

Thanks

Now there's one more catch, I need to extract the data and store in a separate files with the same name given with in the pattern ( IB_QEF_INF_1244_DMFullBox_job and IB_QEF_INF_1244_DMGRPFPMSIn_Box).

$ awk '/\/\*/{print $3}' input.txt
IB_QEF_INF_1244_DMFullBox_job
IB_QEF_INF_1244_DMGRPFPMSIn_Box
IB_QEF_INF_1244_DMGRPFPMS_Box

---------- Post updated at 01:27 PM ---------- Previous update was at 01:25 PM ----------

For storing all jobs jil information, run the below command

 
awk '/\/\*/{print $3}' input.txt | while read job; do autorep -q -J $job > $job; done

Thanks for the help.
But probably I was not clear with the requirements. :frowning:

In my case, the autosys jil files are not stored in server. so cant use autorep command.
The definitions are stored in a separate file and from that I want 1 file for each of the job definitions.

E.g. consider if my file contains 20 job definitions then I need 20 different files containing job definition of each one of them.

The awk command which u have provided will only extract the different job names from my file but not the definition.:wall:

is one of your box job contains one more box job inside ?

 
box
||
---box
     ||---box 

My files contains all the job definitions of one server (irrespective of box/child jobs).
I created this file using a perl script during migration of Autosys 4 to Autosys 11.

Say If I have 20 jobs in my server then the file lists all 20 jobs (box+child) in a random order.

Now what I need is 20 different files for 20 jobs with their corresponding definitions.
Considering the above eg

  • ----------- IB_QEF_INF_1244_DMFullBox_job------------*/
    ##########some data##########
    ##########some data##########

/* ----------- IB_QEF_INF_1244_DMGRPFPMSIn_Box -----------*/

##########some data##########
##########some data##########
/* ------------- IB_QEF_INF_1244_DMGRPFPMS_Box ---------- */
##########some data##########
##########some data##########

Now what I need is 3 different files (IB_QEF_INF_1244_DMFullBox_job,IB_QEF_INF_1244_DMGRPFPMSIn_Box and IB_QEF_INF_1244_DMGRPFPMS_Box ) with their corresponding definitions (some data)

awk '/[Bb]ox/{a=$3;print >> a} !/[Bb]ox/ {print >>a}' input.txt

itkamaraj, this too will not help since the names doesn't necessarily contain the 'box' word and I want the job definitions too with the different files.

Can't we search for the next occurence of the string /* ------------- IB_QEF_INF_1244 and fetch all the data in between the two occurences and then store the data in a separate file named by the job name which can be fetched using the first command whihc u provided.

I am a beginner in awk/sed, so couldn't formulate a command/script which will do the same.

awk '/\/\*.*IB_QEF_INF_1244/{a=$3;print >> a} !/[Bb]ox/ {print >>a}' input.txt
awk '/\/\*.*IB_QEF_INF_1244/{a=$3;print >> a} !/\/\*.*IB_QEF_INF_1244/ {print >>a}' input.txt

/: Event not found

Its giving an error :wall:

The given data is not in a fixed format. However try..

awk '/IB_QEF/{f=0} f{print >v}/IB_QEF_/{f=1;v=$3;next}' inputfile

try this

# awk '/\/\*.*IB_QEF_INF_1244.*\*\//{w=0}w;/\/\*.*IB_QEF_INF_1244.*\*\//{w=1}' file >output

regards
ygemici

The aboce code is also giving the same error.
Please consider the below data sample.

/* ----------------- IB_IBD_1244_ibaqdb2_LN_DMFullBox_job ----------------- */
insert_job: IB_IBD_1244_ibaqdb2_LN_DMFullBox_job   job_type: b
#owner: ibaqdb
permission: wx, mx, gx
date_conditions: 1
days_of_week: all
start_times: "00:00"
condition: notrunning(IB_IBD_1244_ibaqdb2_LN_DMLoadHistPipe) and notrunning(IB_IBD_1244_ibaqdb2_LN_DMIntraBox_job) and notrunning(IB_IBD_1244_ibaqdb2_LN_DMLoan_GEMFull) and notrunning(IB_IBD_1244_ibaqdb2_LN_DMGRPFPMS_Box) and notrunning(IB_IBD_1244_ibaqdb2_LN_DMGRPFPMSIn_Box)
description: "Rerun=0; 105; Please only email on all alarms DL-IBD+-PSM"
job_terminator: 1
max_run_alarm: 120
alarm_if_fail: 1
timezone: London

/* ----------------- IB_IBD_1244_ibaqdb2_LN_DMGRPFPMSIn_Box ----------------- */
insert_job: IB_IBD_1244_ibaqdb2_LN_DMGRPFPMSIn_Box   job_type: b
#owner: ibaqdb
permission: wx, mx, gx
date_conditions: 1
days_of_week: sa
start_times: "12:00"
condition: notrunning(IB_IBD_1244_ibaqdb2_LN_DMGRPFPMS_Box) and success(IB_IBD_1244_ibaqinf2_LN_LdDealogic)
description: "Rerun=1; 105; Please only email on all alarms DL-IBD+-PSM"
job_terminator: 1
max_run_alarm: 120
alarm_if_fail: 1
timezone: London

---------- Post updated at 05:19 AM ---------- Previous update was at 05:17 AM ----------

Now considring the above code, I need to generate 2 different files having definition for the two jobs.

try this...

 
awk '{if($0~/---/){a=$3;print >>a}else{print >>a}}' input.txt
1 Like

Thanks to all who provided help. The last post helped. Thanks again

Please understand the output generated from the above commands are through pattern matching with the data provided by you. If there is change in pattern some where in the data, some commands/solutions would not work as expected. Your post #5 and #12 differs. Ensure you post the data with no inconsistency

nawk '/-- IB/{f=0} f{print >v}/-- IB/{f=1;v=$3;next}' inputfile