finding text in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers finding text in a file
# 1  
Old 12-20-2007
finding text in a file

How do i find text string in a file if i have no idea where the file is?
What I am trying to do is find an email address in a file and have no idea where the file is.
Thanks
# 2  
Old 12-20-2007
Code:
find . -type f | xargs grep "email@addr"

# 3  
Old 12-20-2007
Quote:
Originally Posted by porter
Code:
find . -type f | xargs grep "email@addr"

I suspect that won't give you the filename it found it in...
Try:
Code:
find . -type f -exec grep "email@addr" {} /dev/null \;

The /dev/null causes grep to see that it has multiple files to look through so it lists the filename along with any matches.
# 4  
Old 12-20-2007
Thanks Ill give it a try..Lots of places it could be hiding
# 5  
Old 12-25-2007
Quote:
Originally Posted by Smiling Dragon
I suspect that won't give you the filename it found it in...

Try:
Code:
find . -type f -exec grep "email@addr" {} /dev/null \;

The /dev/null causes grep to see that it has multiple files to look through so it lists the filename along with any matches.
I don't understand why you think it does not give you the file name.
It should work fine as well as the below code.
# 6  
Old 01-06-2008
It depends on the version of grep.
As an example, the grep that comes with solaris doesn't:
Code:
[10 T2K:~]$ grep localhost /etc/hosts
127.0.0.1       localhost
[10 T2K:~]$ grep localhost /etc/hosts /dev/null
/etc/hosts:127.0.0.1    localhost

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding pattern in a text file and returning a part of the word

Dear All, assume that we have a text file or a folder of files, I want to find this pattern followers*.csv in the text file , and get * as the output. There are different matches and * means every character. Thank you in advance. Best, David (1 Reply)
Discussion started by: davidfreed
1 Replies

2. Shell Programming and Scripting

Finding a text file from a group of zip files without unzipping

HI , There are more than 100 zip files in a directory and i wanted to see if there is a max1157.txt file in any of the zip files without actually unzipping them. Could you please help. Thanks in Advance. Karthik. (6 Replies)
Discussion started by: karthikk0508
6 Replies

3. Shell Programming and Scripting

Finding the second last column value from a text file

Can any one tell me how to get the second last column value from the text file, which has different record size for each record. I know how to get the last column using awk and print statements, but I am unable to get the second last column value from the file. (4 Replies)
Discussion started by: naveen_sangam
4 Replies

4. Shell Programming and Scripting

Finding the last column value from a text file

Hi, I need to find out the last column value from a text file which is delimited by a tab. The issue here is the last column# for each record can be different i.,e, 1st record can have the last column as 15 and the second record can have the last column as "17". I have to search a string... (3 Replies)
Discussion started by: naveen_sangam
3 Replies

5. Shell Programming and Scripting

Finding a string in a text file and posting part of the line

What would be the most succinct way of doing this (preferably in 1 line, maybe 2): searching the first 10 characters of every line in a text file for a specific string, and if it was found, print out characters 11-20 of the line on which the string was found. In this case, it's known that there... (13 Replies)
Discussion started by: busdude
13 Replies

6. Shell Programming and Scripting

Help with finding text in file

Hello, Please help me with this. I have two files. file1.txt and file2.txt File1 contains text as below txt1 txt2 txt3 txt4 txt5 txt6 txt7 txt8 File2 contains text as below $1 $2 $3 $4 $5 $6 $7 $8 $9 ----------------------------- txt1 txt2 - - - 0 2 8 -*- txt0 txt7 - - - 1 4 8... (3 Replies)
Discussion started by: tenderfoot
3 Replies

7. Shell Programming and Scripting

add newline in file after finding specific text

Hi All, I am tring to insert a newline with "/" in a text file whenever there is the text "end;" right now I have inside file: . . end; I want to have: . . end; / I tried doing the following within the file :g/^end;/s//end; \/ / (4 Replies)
Discussion started by: jxh461
4 Replies

8. Shell Programming and Scripting

Finding out if there is text in a file.

I have a script that when run creates 4 other text files. Sometimes a couple of these text files are empty. So what I am trying to do is find out if there is text in the file and if not delete the file. What I have so far is the following script. I am just not sure how to return a true value... (9 Replies)
Discussion started by: iCONAN
9 Replies

9. UNIX for Dummies Questions & Answers

finding text inside file

Hi everyone I have a small problem i cant find a soloution to... I'm using digital unix and have to find out all the files which have a certain string inside them and i dont know how to do it. *This search is done as root. *All files from '/' to the last directory should be searched for... (3 Replies)
Discussion started by: dindan100
3 Replies

10. Filesystems, Disks and Memory

finding out the pid for a busy text file

Can some one please tell me how to find out the proccess ID that is holding up a file. I am attempting to remove a file and I am getting a message stating that it is busy. i.e rm filename filename: 777 mode ? (y/n) y rm: filename not removed. Text file busy Thanks in advance. (1 Reply)
Discussion started by: jxh461
1 Replies
Login or Register to Ask a Question