![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell script to search for text in a file and copy file | imeadows | UNIX for Dummies Questions & Answers | 9 | 11-12-2008 09:12 PM |
| File extension search and copy | bsandeep_80 | UNIX for Advanced & Expert Users | 20 | 04-04-2008 10:19 AM |
| searching for filenames with search strings in another file | pathanjalireddy | Shell Programming and Scripting | 3 | 06-08-2005 05:35 AM |
| How can you copy strings? | area | High Level Programming | 3 | 05-15-2002 12:17 PM |
| Search for strings | lesstjm | UNIX for Dummies Questions & Answers | 5 | 04-26-2002 09:58 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Search for strings & copy to new file
Hi All,
I am just learning shell programming, I need to do the following in my shell script. Search a given log file for two\more strings. If the the two\more strings are found then write it to a outputfile else if only one of the string is found, write the found string in one output file and others in other output file. Is it possible to do it? If so please share the code Thanks Amit |
|
||||
|
use if []; then .....else......
use the exit status of grep as condition grep exits with 0 if the string is found, 1 if not found and 2 if the file is not there. then use > to redirect your output to a file and >> to append your output to the file. have fun! |
|
||||
|
Hi Lami
Thanks for the info. My requirement is some what like this...can you shed somemore light on this I am trying to write a shell script which will scan a log file for three strings ie success image1, success image2, success image3. My shell is tcsh If all the 3 strings are found then insert the 3 strings to a file1 and send mail to developers with file1 If all 3 are note found copy the strings to a file2 and send file2 to developers. Similarly, if string image1 & image2 are found and image3 missing...then insert the string image1 & image2 to file-1 and insert the string image3 to file-2 and send a mail attaching both file1 & file2 to developer. I tried if - else but that is making the scrip longer, Sorry for the troubles Amit |
| Sponsored Links | ||
|
|