find/grep returns no matches


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find/grep returns no matches
# 1  
Old 02-14-2010
find/grep returns no matches

Hi all!

I've faced with very unintelligible error using find/grep like this:

Code:
root@v29221:~# find /var/www/igor/data/www/lestnitsa.ru | grep u28507

I get nothing as a result, but:

Code:
root@v29221:~# grep u28507 /var/www/igor/data/www/lestnitsa.ru/_var.inc               
$db_name = 'u28507';
$link = mysql_connect ('u28507.mysql.masterhost.ru', '*', '*') or die ("Could not connect");

It drives me crazy, please help to figure this out.
# 2  
Old 02-14-2010
Hi.

You've taken the filename as input to grep, so you are grepping on the filename, not on the file contents, as you imagined.

try using
Code:
find ... | xargs grep u28507

or better
Code:
find ... | xargs -I{} grep u28507 {}

Code:
$ cat file1
start
  u28507
end

$ find . -name file1 | grep u28507                   

$ find . -name file1 | xargs grep u28507 
  u28507

$ find . -name file1 | grep file1 
./file1


Last edited by Scott; 02-14-2010 at 07:45 AM..
# 3  
Old 02-14-2010
Thank you very much! What a stupid mistake... :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Linux find command returns nothing

Under one of my directories on server I have more than 500 files with different type and name. When I run the find command to list the files with 'ABC_DEFGH' in the begining of its name and older than 20 days, nothing is return as result. Though I know there are more than 400 files which their name... (10 Replies)
Discussion started by: Home
10 Replies

2. Shell Programming and Scripting

rm -rf ab returns find: `./ab': No such file or directory

Hi Gurus. This is driving me a bit batty. I now if must be a simple matter but I cant find anything that references it. I have a housekeeping script that searches for some huge dump directories then removes them using rm -rf. find ./ -name 'ab' -exec rm -rf {} \; This works but always... (7 Replies)
Discussion started by: rinser
7 Replies

3. Shell Programming and Scripting

If test grep.... always returns 0 status

Hi all. I am trying to compare and filter two files. I have a bigfile.txt of names and ids and a smallfile.txt of ids only. What I am trying to do is use a while read loop to read the ids in the bigfile and then echo the name and id only if the id exists in the small file. Basically, I'm trying to... (5 Replies)
Discussion started by: jameswatson3
5 Replies

4. UNIX for Dummies Questions & Answers

grep returns many values into a variable error

I get an error when I grep my results into a variable when the grep finds more than one file. FND="$(find ediout* -mmin -60)" if ; then STR="$(find ediout* -mmin -60 -exec grep -l "ERRORS Encountered" {} +)" fi When there is only one ediout file it works fine. How do I... (11 Replies)
Discussion started by: aispg8
11 Replies

5. Shell Programming and Scripting

Using grep returns partial matches, I need to get an exact match or nothing

I’m trying to modify someone perl script to fix a bug. The piece of code checks that the zone name you want to add is unique. However, when the code runs, it finds a partial match using grep, and decides it already exists, so the “create” command exits. $cstatus = `${ZADM} list -vic | grep... (3 Replies)
Discussion started by: TKD
3 Replies

6. Shell Programming and Scripting

Grep returns nothing

Hi all, I am trying to grep a .txt file for a word. When I hit enter, it returns back to $ The file is 4155402 in size and is named in this way: *_eveningtimes_done_log.txt I use this command, being in the same directory as the file: grep -i "invalid" *_eveningtimes_done_log.txt ... (16 Replies)
Discussion started by: DallasT
16 Replies

7. Shell Programming and Scripting

If the grep command returns any result set

my intension is to use a grep command inside the shell script and if any row is returned or not.. depending on the resultset i have to code on further. how to check this i mean.. could anyone help me out with the if condition how to use it here !! (4 Replies)
Discussion started by: gotam
4 Replies

8. UNIX for Dummies Questions & Answers

| help | unix | grep - Can I use grep to return a string with exactly n matches?

Hello, I looking to use grep to return a string with exactly n matches. I'm building off this: ls -aLl /bin | grep '^.\{9\}x' | tr -s ' ' -rwxr-xr-x 1 root root 632816 Nov 25 2008 vi -rwxr-xr-x 1 root root 632816 Nov 25 2008 view -rwxr-xr-x 1 root root 16008 May 25 2008... (7 Replies)
Discussion started by: MykC
7 Replies

9. UNIX for Dummies Questions & Answers

Grep without returns...

Is there a command where I can pipe my grep into it and it will output it with spaces rather than returns? Example I want to turn prompt$ grep blah file blah blah into this prompt$ grep blah file | someCommand blah blah (1 Reply)
Discussion started by: mrwatkin
1 Replies

10. Shell Programming and Scripting

FIND returns different results in script

When I execute this line at the command prompt I get a different answer than when I run it in a script? Any ideas on how to resolve? I'm trying to find all files/dir in a directory except files that start with the word file. Once I get this command to work, I will add the "delete" part to the... (6 Replies)
Discussion started by: blt123
6 Replies
Login or Register to Ask a Question