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
Find and store files based on FileName and Modified Time edisonantus UNIX for Advanced & Expert Users 2 02-19-2008 10:25 AM
file moving based on file content melvyn.cochrane Shell Programming and Scripting 12 02-15-2008 02:10 AM
Adding filename into file content missutoomuch Shell Programming and Scripting 1 11-11-2005 12:02 PM
find the same content in the file ust UNIX for Dummies Questions & Answers 4 03-25-2005 01:55 AM
search for hardlinks based on filename via find command hunternjb UNIX for Dummies Questions & Answers 2 03-26-2001 09:07 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-01-2001
Registered User
 

Join Date: Jun 2001
Posts: 2
Stumble this Post!
find filename based on file content

There is a flat file on my system which contains email addreses of people in my company. This file is utilized when sending notifications for various things. However nobody knows where this file is located or what it is named. The only thing we know is the email address of a user who needs to be deleted from this file. Is there a command to search through a file system and return results based on the content of the file? For example, if I wanted to see all filenames and locations where jkoller@jkoller.com was in the file how would I do that? Thanks!!!
Forum Sponsor
  #2 (permalink)  
Old 06-01-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Stumble this Post!
Try this command:

find / -type f -exec grep email@host {} /dev/null \;
  #3 (permalink)  
Old 06-01-2001
Registered User
 

Join Date: Jun 2001
Posts: 2
Stumble this Post!
THANK YOU! THAT WORKED!!
  #4 (permalink)  
Old 06-02-2001
Registered User
 

Join Date: Apr 2001
Posts: 25
Stumble this Post!
Hey PxT,

The /dev/null is a nice twist - I'm not sure I understand why/how this works - I would have used a -l option on the grep to list the files. But showing the file & pattern found is nice.


Can you explain what this is doing? Is the behavior related to grep or to the find?

  #5 (permalink)  
Old 06-02-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Stumble this Post!
One of the features of grep is that if you specify more than one file to search it will show any matches prefixed by the filename. So I specify /dev/null as a second file to search. It will never match, and will always exist. You could really use any file, but /dev/null is a safe choice.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0