Operating System - HP-UX
1751974 Members
4541 Online
108784 Solutions
New Discussion юеВ

Help with Unix Bourne Shell Script - Loop

 
SOLVED
Go to solution
Laurie A. Krumrey
Regular Advisor

Help with Unix Bourne Shell Script - Loop

Hi All,

I am trying to write a unix script to
read in the below file:

*************************************
AUTOSTUFFdsklfdskl
Date and Time
job definition change

owner:tom
jobname: report1
****************************************
AUTOSTUFFdsklflkdfkl
Date and Time
sendevent issued

owner:sally
jobname: report2
****************************
ETC...

I want my script to just report an output
file, like an audit report. I only want to
copy the information between the "******"
if the 3rd says "job definition changes", that's when I want to print all the info
between the "***********".

In other words, I don't care about the
sendevent issued stuff, so I don't want to
print that stuff between the "******".

I am having problems writing a shell script
to loop within the the "***********"

Thank You,
Laurie

Happiness is a choice
11 REPLIES 11
A. Clay Stephenson
Acclaimed Contributor

Re: Help with Unix Bourne Shell Script - Loop

Hi Laurie:
If it were me, I would do this in awk or perl. It's duck soup in those tools. If you like, when I get to the office in the morning I'll adapt one of my existing awk scripts during my coffee break. If you haven't whipped it by then if you attach a real sample of your input (so the pattern matching is exact) I think I can alter my script in under 5 minutes.

Regards, Clay
If it ain't broke, I can fix that.
Carlos Fernandez Riera
Honored Contributor

Re: Help with Unix Bourne Shell Script - Loop

awk ' $1 == "****************************************"
{ getline; l1=$0; getline ; l2=$0; getline; l3=$0; getline;getline; l5=$0; getline; l6=$0}
l3 ~ "job definition change" { print l1
print l2
print l3
print l5
print l6}' file
unsupported
Laurie A. Krumrey
Regular Advisor

Re: Help with Unix Bourne Shell Script - Loop

Here's an exact copy of the input file:
--------------------------------------------
autosys2@droopy
05/07/2001 11:09:57
autotrack change

level: 1
::::::::::::::::::::::::::::::::::::::::::

AUTOSYS2@IFTCMSTR
05/07/2001 11:22:31
sendevent issued

eoid: ACEz10003652
job_name: CAP_BERG_BERGER
command: sendevent "-E" "FORCE_STARTJOB" "-P" "10"
::::::::::::::::::::::::::::::::::::::::::::::

AUTOSYS2@IFTCMSTR
05/07/2001 11:23:54
job definition change

job_name: MOO_FNBO_MON-3
box_name: MOO_FNBO_MON
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

AUTOSYS2@IFTCMSTR
05/07/2001 11:24:05
job definition change

job_name: MOO_FNBO_MON-4
box_name: MOO_FNBO_MON
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

AUTOSYS2@IFTCMSTR
05/07/2001 11:24:11
job definition change

job_name: MOO_FNBO_MON-E
box_name: MOO_FNBO_MON
::::::::::::::::::::::::::::::::::::::::::::::

AUTOSYS2@IFTCMSTR
05/07/2001 11:24:17
job definition change

job_name: MOO_FNBO_MON-E-NFY
box_name: MOO_FNBO_MON
:::::::::::::::::::::::::::::::::::::::::::::::

AUTOSYS2@IFTCMSTR
05/07/2001 11:24:23
job definition change

job_name: MOO_FNBO_MON-4-NFY
box_name: MOO_FNBO_MON
:::::::::::::::::::::::::::::::::::::::::::::::

AUTOSYS2@IFTCMSTR
05/07/2001 11:24:29
job definition change

job_name: MOO_FNBO_MON-3-NFY
box_name: MOO_FNBO_MON
@
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

AUTOSYS2@IFTCMSTR
05/07/2001 11:25:02
sendevent issued

eoid: ACEz10003653
job_name: MOO_FNBO_MON-3
command: sendevent "-E" "FORCE_STARTJOB" "-"10"
--EOF----

Note: This files begins with autosys2droopy and
ends without the ::::::::::::::::.

It can be variable length and we only want to
print out the stuff between the :::::::::::
if the 3rd line says "job definition change".

THANK YOU SO MUCH...
Laurie
Happiness is a choice
A. Clay Stephenson
Acclaimed Contributor

Re: Help with Unix Bourne Shell Script - Loop

Ok Laurie,
I'm on my coffee break and I found the script that was close; the mod's took about 2 minutes.

The attached shell script does a 'here docs' to build an awk script then invokes awk to read stdin and write to stdout. I noticed that you changed the delimiters from '*' to ':'.

You would use it something like this:
laurie.sh < my_infile > my_outfile

Enjoy, Clay

If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Help with Unix Bourne Shell Script - Loop

Ok Laurie,
I'm on my coffee break and I found the script that was close; the mod's took about 2 minutes.

The attached shell script does a 'here docs' to build an awk script then invokes awk to read stdin and write to stdout. I noticed that you changed the delimiters from '*' to ':'.

You would use it something like this:
laurie.sh < my_infile > my_outfile

Enjoy, Clay

If it ain't broke, I can fix that.
Laurie A. Krumrey
Regular Advisor

Re: Help with Unix Bourne Shell Script - Loop

Clay,

I did not get your attached file.

Could you just email it to me at

LAKRUMREY@STATESTREETKC.COM

Thank you,
Laurie
Happiness is a choice
Laurie A. Krumrey
Regular Advisor

Re: Help with Unix Bourne Shell Script - Loop

Clay,

I didn't give you enough points so if the
script works I want to give you 10 points.
So post another email here.

Laurie
Happiness is a choice
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Help with Unix Bourne Shell Script - Loop

Sorry, Laurie:
I got a 'page cannot be displayed' error after replying but if you look at the posting just above (now my 2nd previous , you,ll see the attachment).

If you still have trouble, I'll email you.

Clay
If it ain't broke, I can fix that.
David Totsch
Valued Contributor

Re: Help with Unix Bourne Shell Script - Loop

sed -n "/job definition changes/,/^:::::/ p"