[HPADM] SUMMARY Scripting question.

From: Thomas Northup (thomaslnorthup@yahoo.com)
Date: Wed Jul 28 2004 - 21:07:37 EDT


Scripting question.

I want to grep a file for something and if I find it I want that line and the next 7 lines.

How would I go about doing that?

TIA, will summarize.

Tom

Several people pointed out it can not be done using the grep that comes with HP-UX and that I should get GNU grep witch supports this type of function.

I got alot of great ideas on how to do it using awk and sed.

I decided to go with what Thomas Stout sugessted. I also built in an if then to check if there are any and if not email that none were found and if there are some then email the list of them.

ERROR=`/usr/bin/grep "whatIamlookingfor" filetolookin | /usr/bin/grep -v grep | /usr/bin/wc -l`

if [ "$ERROR" = 0 ]

then

/usr/bin/echo "whatIamlookingfor not found" | /usr/bin/mailx -s 'whatIamlookingfor not found' someone@somewhere.com

else

/usr/bin/cat filetolookin | sed -n '/whatIamlookingfor/{;N;N;N;N;N;N;p;}' | /usr/bin/mailx -s 'whatIamlookingfor found' someone@somewhere.com

fi

____________________________________________________________________________________________
Do you eBay (Click Here)

                
---------------------------------
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:42 EDT