How To Pipe Find To Grep?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How To Pipe Find To Grep?
# 1  
Old 05-25-2012
How To Pipe Find To Grep?

hi

what wrong with my syntax here?

Code:
find / -name "*dhcp*" | grep -l -r 'timeout'

thanks
# 2  
Old 05-25-2012
Hi,

try with

Code:
find / -name "*dhcp*" | grep  'timeout'

BR//

nitesh
# 3  
Old 05-25-2012
You're grepping on the filename, not the file contents.

Use -exec grep timeout {}, or pipe the find output through xargs.

i.e.
Code:
find / -name "*dhcp*" -exec grep timeout {} \;

And do you really want to search the entire system? That could take seconds, it could take hours, depending.
# 4  
Old 05-25-2012
Quote:
Originally Posted by Scott
You're grepping on the filename, not the file contents.

Use -exec grep timeout {}, or pipe the find output through xargs.

i.e.
Code:
find / -name "*dhcp*" -exec grep timeout {} \;

And do you really want to search the entire system? That could take seconds, it could take hours, depending.
To expand on this, if you want the file name, add "l" to the grep statement and you might want to ignore case:

Code:
find / -name "*dhcp*" -exec grep -il timeout {} \;


Last edited by dagamier; 05-25-2012 at 02:04 PM.. Reason: fixed my find
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep:pipe delimited output

Hi, I am trying to search for a string in a file and print all the matched lines as pipe delimited format. My command is cat m_gid_trans.XML|grep -i '<TABLEATTRIBUTE NAME ="Lookup cache directory name"' The output I am getting is <TABLEATTRIBUTE NAME ="Lookup cache directory name"... (4 Replies)
Discussion started by: sampoorna
4 Replies

2. Shell Programming and Scripting

pipe search pattern into a grep

comm -13 tmpfile tmpfile2 | grep -v <filename> >newfile so i want to 1. find records in 1 file bot not in another 2. The output of the first part is 1 field in a file with many fields. 3. find all the records that do not have the value piped from step #1 4. redirect to a new file ... (4 Replies)
Discussion started by: guessingo
4 Replies

3. UNIX for Dummies Questions & Answers

Bash - CLI - grep - Passing result to grep through pipe

Hello. I want to get all modules which are loaded and which name are exactly 2 characters long and not more than 2 characters and begin with "nv" lsmod | (e)grep '^nv???????????? I want to get all modules which are loaded and which name begin with "nv" and are 2 to 7 characters long ... (1 Reply)
Discussion started by: jcdole
1 Replies

4. UNIX for Dummies Questions & Answers

Pipe grep to rm

We have a number of OS X 10.6 machines who have home folders with incorrect permissions, which are causing managed prefs not to be applied correctly and not allowing saving. I need to delete all home folders whose name is numerical and modified before a certain date. I'm not sure of the date part... (2 Replies)
Discussion started by: airlocksniffer
2 Replies

5. Shell Programming and Scripting

pipe result from grep

Trying to create a command line script to look for all files matching a pattern, grep for a specific value in each file, and write out the filename long list. It's possible the filename won't containe the value. { echo “Running....” for fname in 811_Intermediate_File_* do grep -l... (3 Replies)
Discussion started by: gavineq
3 Replies

6. UNIX Desktop Questions & Answers

How to grep and pipe to mput ftp

I am ptting the following into an FTOP script. date=`TZ="aaa24" date +'%Y%m%d'` # this gets Yesterday date . . . . mput < 'l | grep $Vdate' # the idea to grep a listing from a directory that has yesterday date in its file name then put it in the remote FTP server. How can I get it... (4 Replies)
Discussion started by: raouf@comcast.n
4 Replies

7. Shell Programming and Scripting

pipe output of grep to sed?

Is there a way I can do this: search for text and replace line containing matched text with a different line? For example: "I want to replace text" I want to search for replace and then change the line to I am perplexed. Hope that makes sense. Thanks in advance. (4 Replies)
Discussion started by: arsh
4 Replies

8. Shell Programming and Scripting

problem using a pipe to grep

Hello ! I want to process a text file in order to extract desired data using sed and grep... Now I am facing a problem piping to grep... nothing happens.. The text consists of blocks of 3 lines that may (or not) contain the Desired data. the desired data is on each 2... (4 Replies)
Discussion started by: ShellBeginner
4 Replies

9. Shell Programming and Scripting

pipe grep command

Hi all, Can someone help me with the following problem. I am executing the following command: (search for occurences of 'error' in files that match cl-*.log expression) > grep -cw -i --max-count=1 'error' cl-*.log this command outputs: cl-apache.log:1 cl-apache_error.log:1... (3 Replies)
Discussion started by: epro66
3 Replies
Login or Register to Ask a Question