![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | 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 and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
Code:
#!/bin/bash my_file1="/mylocation/myfile1.log" my_file2="/mylocation/myfile2.log" my_string="Match Found" tail -F "$my_file1" "$my_file2" | while read line ; do if test -n "$(echo "$line" | grep "$my_string")" ; then echo "Match found!" exit 0 else exit 1 fi done The above program will wait for both file1 and file2. Whenever it finds a file with proper string match, condition triggers. The else condition to quit the program (exit 1) has to be used wisely. If you are looking for some 'lock' files with specific string content, the program can wait for the file(s) to occur in specific path and act immediately. If the file is a log file and always present in path, it is not wise to use the else logic, it will just quit the program after reading the first line itself. meharo |
|
|||
|
to recursively search a string in files in a dir try
find . -name <name / pattern of your file> -print | xargs grep <string to be searched> 2>/dev/null Cheers |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Search for string in a file and extract another string to a variable | daikeyang | Shell Programming and Scripting | 6 | 03-20-2009 08:45 PM |
| How to search a string in a file. | prathap | UNIX for Dummies Questions & Answers | 1 | 07-17-2007 03:41 AM |
| String search in log file | sliver | Shell Programming and Scripting | 1 | 07-12-2006 08:09 AM |
| appending string to text file based on search string | malaymaru | Shell Programming and Scripting | 1 | 06-09-2006 09:53 AM |
| please help me to search string in a file ...... | swamymns | Shell Programming and Scripting | 2 | 02-01-2006 12:20 PM |