The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
What is the Best way to search files for a string?? 35Soinc UNIX for Dummies Questions & Answers 15 03-25-2008 04:34 PM
Search a string from list of input files sivakumarvenkat UNIX for Dummies Questions & Answers 2 03-08-2006 06:08 PM
Search files for a string in the remote machine a_rivu UNIX for Dummies Questions & Answers 2 06-14-2005 03:31 PM
I dont want to know any search engines memattmyself Shell Programming and Scripting 1 05-09-2002 12:09 PM
Search all files for specific string sureshy UNIX for Dummies Questions & Answers 4 03-06-2002 12:28 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-04-2004
tonydsam tonydsam is offline
Registered User
  
 

Join Date: May 2004
Posts: 17
Unhappy Search for Files that DONT contain a string

How do I search for files that dont contain a certain string? I am currently trying

find ./logs -size +1c -exec grep -l 'Process Complete' {} \; -exec ls -l {} \; >
$TOD

Which gives me files that are reater han 0 file size and contain the string 'Process complete' but I want files that DONT contain Process Complete. If i use the -v option for grep it still doesnt work!
  #2 (permalink)  
Old 05-04-2004
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,796
Try

Code:
find ./logs -size +1c  > t._tmp
while read filename
do
     grep -q "Process Complete" $filename
     if [ $? -ne 0 ] ; then
             echo $filename
     fi
done < t._tmp
rm -f t_tmp

  #3 (permalink)  
Old 05-04-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Re: Search for Files that DONT contain a string

Quote:
Originally posted by tonydsam
How do I search for files that dont contain a certain string? I am currently trying

find ./logs -size +1c -exec grep -l 'Process Complete' {} \; -exec ls -l {} \; >$TOD

Which gives me files that are reater han 0 file size and contain the string 'Process complete' but I want files that DONT contain Process Complete. If i use the -v option for grep it still doesnt work!
Just negate the condition with a "!"

find ./logs -size +1c ! -exec grep -l 'Process Complete' {} \; -exec ls -l {} \; >$TOD
  #4 (permalink)  
Old 05-05-2004
tonydsam tonydsam is offline
Registered User
  
 

Join Date: May 2004
Posts: 17
This doesnt seem to be working as it is still picking up the files with Process Complete in them. I have tried moving the ! around but still no joy. 'Process Complete' should only be on the last line of the file if that helps.

Last edited by tonydsam; 05-05-2004 at 04:26 AM..
  #5 (permalink)  
Old 05-05-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
I think that your problem is that you are using find to grep on the ./logs directory itself and not just on the files in that directory. You need to restrict the find to only grep within plain files.

Lets test this theory, using some test files...

$ mkdir logs
$ echo 'Process Complete' > logs/log1
$ echo 'otherwise' > logs/log2

...first find files that do contain the string...

$ find ./logs -size +1c -exec grep -q 'Process Complete' {} \; -print
./logs/log1

...as expected. Now find files that do NOT contain the string...

$ find ./logs -size +1c ! -exec grep -q 'Process Complete' {} \; -print
./logs
./logs/log2

...woah! What's that "./logs" thing doing there?! If I was using "-exec ls -l {} \;" then it would return every file in the directory! Better restrict the find to plain files...

$ find ./logs -type f -size +1c ! -exec grep -q 'Process Complete' {} \; -print
./logs/log2

...OK!
  #6 (permalink)  
Old 05-02-2006
moneybagsxp's Avatar
moneybagsxp moneybagsxp is offline
Registered User
  
 

Join Date: May 2006
Location: USA
Posts: 1
Thumbs up

Quote:
Originally Posted by Ygor

...woah! What's that "./logs" thing doing there?! If I was using "-exec ls -l {} \;" then it would return every file in the directory! Better restrict the find to plain files...

$ find ./logs -type f -size +1c ! -exec grep -q 'Process Complete' {} \; -print
./logs/log2

...OK!
Bravo, Ygor! I came to these forums KNOWING that the answer must dwell within. Registered, searched, and found--1st try

Thank you!

For me, I wanted to find any instance of our "old" domain name, while EXCLUDING email addresses. Finally!


Code:
find . -type f ! -exec grep -q '@olddomain.com' {} \; -exec grep -q 'olddomain.com' {} \; -print

  #7 (permalink)  
Old 05-05-2004
tonydsam tonydsam is offline
Registered User
  
 

Join Date: May 2004
Posts: 17
Thank you, this does seem to work but I get an error with the -q option so I have changed it to -l, what should it do though ?


Last edited by tonydsam; 05-05-2004 at 11:23 AM..
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 11:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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