The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to grep for a word and display only the word ananthmm UNIX for Dummies Questions & Answers 6 05-29-2008 05:00 AM
grep for word eltinator Shell Programming and Scripting 5 04-22-2008 05:07 PM
grep a word from a line Orbix UNIX for Dummies Questions & Answers 2 12-23-2007 08:52 AM
Grep for X character on a word jjoves UNIX for Dummies Questions & Answers 5 08-06-2004 02:14 AM
How to grep more then one word? roco UNIX for Dummies Questions & Answers 5 10-18-2002 07:43 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-21-2008
Registered User
 

Join Date: Mar 2006
Posts: 3
Grep for Particular Word

we should do a grep for the trailer record in a file file.out (TRL is searching word)
If the trailer is not found, the script should go to sleep for a period of time to be determined, then do the grep again. This way, the script will stay in a loop and not exit until the entire file has been transmitted to this directory. That will be the internal do loop.Please suggest me to how can i do that in a shell script.
Thanks
Reddi
Reply With Quote
Forum Sponsor
  #2  
Old 01-21-2008
Registered User
 

Join Date: Jan 2008
Posts: 12
see if this helps ...

The main.sh is a dummy script that writes some info to outfile.

team$ cat main.sh
#!/usr/bin/ksh

i=1

while [ $i -le 5 ] ; do

if [ $i -eq 5 ]; then
echo "TRL" >> outfile
else
echo "Line is $i" >> outfile
fi
sleep 10
i=`expr $i + 1`
done

team$

The main.sh will create a file like this ,

team$ cat outfile
Line is 1
Line is 2
Line is 3
Line is 4
TRL
team$


This monitor.sh will look for the TRL in the trailer record of the outfile, until the TRL is found.

team$ cat monitor.sh
#!/usr/bin/ksh


while [ 1 ] ; do

tail -1 outfile 2>/dev/null | grep "TRL" 2>/dev/null 2>&1

if [ $? -eq 0 ]; then
echo "Trailer Record Found"
break
else
echo "Trailer Record Not Found .. Monitoring "
sleep 5
fi


done

team$


team$ main.sh &
[2] 23378
team$ monitor.sh
Trailer Record Not Found .. Monitoring
Trailer Record Not Found .. Monitoring
Trailer Record Not Found .. Monitoring
Trailer Record Not Found .. Monitoring
Trailer Record Not Found .. Monitoring
Trailer Record Not Found .. Monitoring
Trailer Record Not Found .. Monitoring
TRL
Trailer Record Found
team$


Not sure if I understood your need properly,
Reply With Quote
  #3  
Old 01-22-2008
Registered User
 

Join Date: Mar 2006
Posts: 3
Thanks Rajesh.I modifiled your scrip according to my result.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0