The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-22-2007
amitrajvarma amitrajvarma is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 43
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
  #2 (permalink)  
Old 11-24-2007
lamilami lamilami is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 9
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!
  #3 (permalink)  
Old 11-25-2007
amitrajvarma amitrajvarma is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 43
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0