Languages and Scripting

find files between a certain stanza

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

find files between a certain stanza

Hi

I need help getting information from a file which is between two strings. Basically I have run a ps -fu into a file called zombies. I now need to grep all the defunct procs but display the date the command was run.
here is the script:

#!/bin/ksh

# check for zombies running
DATE=`date`
COUNT=0

if [ -f /usr/dump/JDE/data/in/STU* ] ; then

while [ $COUNT -lt 30 ]
do


echo "\n ####### CHECK PROCS $DATE #########" >>/tmp/zombiecheck.out
ps -fucronlog >> /tmp/zombiecheck.out
sleep 10
COUNT=$(($COUNT+1))
echo "\n ###################################" >> /tmp/zombiecheck.out

done

else

echo "\n ################ NO STU FILES PROCESSED $DATE#####" > /tmp/zombiecheck.out

fi


so I want to display:

####### CHECK PROCS $DATE #########

defunct
defunct
defunct
etc
#####################

####### CHECK PROCS $DATE #########"

etc
etc.

any idea's how I can use awk to achieve this?

many Thanks again guys.

hello
7 REPLIES 7
spex
Honored Contributor
Solution

Re: find files between a certain stanza

Hi Lawrenzo,

How about something simple?

$ grep -E '^#|defunct' < /tmp/zombiecheck.out > /tmp/zombiecheck.out.filtered

PCS
James R. Ferguson
Acclaimed Contributor

Re: find files between a certain stanza

Hi Lawrenzo:

Well, use Perl;

# perl -ne 'print if (/# CHECK/ ... /# CHECK/)' file

Regards!

...JRF...
john korterman
Honored Contributor

Re: find files between a certain stanza

Hi Lawrenzo,

perhaps something like this:

$ awk '$8 ~ /defunct/ {print $5 }' /tmp/zombiecheck.out

regards,
John K.
it would be nice if you always got a second chance
Pete Randall
Outstanding Contributor

Re: find files between a certain stanza

Or with sed:

# print section of file between two regular expressions (inclusive)
sed -n '/Iowa/,/Montana/p' # case sensitive

From "handy one-liners for sed" (attached).


Pete

Pete
lawrenzo_1
Super Advisor

Re: find files between a certain stanza

thanks all for the replies,

one thing about all these one liners ...

The information between

####### CHECK PROCS 0102071600 #########

and

######################

####### CHECK PROCS 0102071615 #########

and

######################

etc etc

Thanks again

hello
lawrenzo_1
Super Advisor

Re: find files between a certain stanza

found the solution which works well:

grep -iE "CHECK PROCS $DATE|defunct|#####################" /tmp/zombiecheck.out

####### CHECK PROCS Thu 1 Feb 12:14:00 2007 #########
cronlog 64230 1 3 0:00
cronlog 78622 1 3 0:00
cronlog 111088 1 4 0:00
cronlog 172654 1 4 0:00
cronlog 180328 1 4 0:00
cronlog 203590 1 4 0:00
cronlog 353808 1 4 0:00
cronlog 382260 1 4 0:00
cronlog 476092 1 4 0:00
cronlog 492992 1 4 0:00
cronlog 503154 1 4 0:00
cronlog 644776 1 4 0:00
cronlog 649456 1 4 0:00
cronlog 685918 1 3 0:00
cronlog 760000 1 4 0:00
cronlog 864828 1 2 0:00
cronlog 913080 1 4 0:00
cronlog 927952 1 3 0:00
cronlog 959492 1 4 0:00
cronlog 982760 1 4 0:00
cronlog 1049558 1 4 0:00
cronlog 1110456 1 3 0:00
cronlog 1118196 1 4 0:00
cronlog 1159696 1 3 0:00
cronlog 1250982 1 3 0:00
cronlog 1296102 1 4 0:00
cronlog 1296372 1 4 0:00
cronlog 1301488 1 4 0:00
cronlog 1359654 1 4 0:00
cronlog 1360516 1 4 0:00
cronlog 1379770 1 4 0:00
###################################
#
magic!

Thanks for all the repsonses
hello
lawrenzo_1
Super Advisor

Re: find files between a certain stanza

cheers
hello