The UNIX and Linux Forums  

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



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 05-16-2008
cdines cdines is offline
Registered User
 

Join Date: Apr 2008
Posts: 7
Angry test egrep not found

Hi,

I want to return failure from my script if a string is NOT found in a file, but I can't work out how to negate my "if". At the moment I have :

if (egrep -i 'search string' filetosearch); then
echo "found"
else
return 2
fi

How can I get rid of the echo bit and just test for "string not found" ? I already know I can use egrep -v to return lines not containing the string, but I actually just want to fail if the search string is not in the file anywhere. Thanks.
Reply With Quote
Forum Sponsor