![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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, |
|
#3
|
|||
|
|||
|
Thanks Rajesh.I modifiled your scrip according to my result.
|
|||
| Google The UNIX and Linux Forums |