recrusive search in GREP


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers recrusive search in GREP
# 1  
Old 11-15-2006
recrusive search in GREP

All,

When i use the below command for recrusive search for a pattern it is not working in my macine I am using HP Unix. Please let me know where i am wrong.

grep -rs "pattern"

i an expecting the same result as find . | xargs grep "pattern" ..

Please let me know.

Thanks,
Arun.
# 2  
Old 11-15-2006
can you tell us what is the error message ?
Example on FreeBSD :
Code:
[root@srv cgi-bin]$ grep -rs /usr/local/ check.pl  
#!/usr/local/bin/perl

# 3  
Old 11-16-2006
showing

grep: illegal option -- r
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] -e pattern_list...
[-f pattern_file...] [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] [-e pattern_list...]
-f pattern_file... [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] pattern [file...]


Is there anyway other thean using Xrags with find command . Please suggest
# 4  
Old 11-16-2006
Well, not all greps support the recursive option. I have used Solaris and HP and never seen the '-r' that you mention here. And why don't you want to use the xargs command?

-edit
To see if you can use a particular option, read the man page of the command for that OS. If the option is not mentioned there, you can't use it.
-/edit
# 5  
Old 11-16-2006
Thanks blowtorch for clearing my long term doubt.
# 6  
Old 11-16-2006
Code:
# find /some/dir -type f -exec grep '^myregex$' {} /dev/null \;

Cheers
ZB
# 7  
Old 11-16-2006
ZB, using the '-l' option achieves (almost) the same result. But I didn't get that /dev/null thing. Can you explain?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

3. Shell Programming and Scripting

Optimizing search using grep

I have a huge log file close to 3GB in size. My task is to generate some reporting based on # of times something is being logged. I need to find the number of time StringA , StringB , StringC is being called separately. What I am doing right now is: grep "StringA" server.log | wc -l... (4 Replies)
Discussion started by: Junaid Subhani
4 Replies

4. Shell Programming and Scripting

Grep string search

Hi All, I'm using aix flavour unix where im trying for the below kind of pattern to search in all the files in a directory. I tried with different possible combinations like grep -ir "out.*\transaction_ctry_code" * etc.... Pattern I'm trying for : out<any thing>country_cd Here i... (0 Replies)
Discussion started by: rmkganesh
0 Replies

5. Shell Programming and Scripting

Grep for search.

hi, i got files delimited by |^ character. eg. apple|^ball|^cat|^dog|^egg i need to find if the above file contains | (pipe ) character inside the data.eg. apple|^ball|^cat|^d|og|^egg. above file contains | character in the dog data. how can i search that. (4 Replies)
Discussion started by: krk
4 Replies

6. Shell Programming and Scripting

grep by limit search

Hi I am in new in unix,can any one tell how to grep the data by limit. suppose I have below data:- is :mSecs is :mSecs is :mSecs is :mSecs requirement is how to grep the data which is having count greater than 1000 msecs only. thanks in adnavce. (2 Replies)
Discussion started by: abhigrkist
2 Replies

7. Shell Programming and Scripting

Grep Search for both First and last word

Hi Pretty sure this is very simple hence im banging my head o the wall as to why i cant get this to work: Im greping against many files where there will be the following string: Date: Thu, Aug 23 2001 09:27 PM (of course values such as date ,time and PM/AM will vary.) Im trying to grep... (1 Reply)
Discussion started by: duonut
1 Replies

8. Shell Programming and Scripting

search using grep

Hi all, I have a folder with many files. I need to get all the filenames with the value "<f id=audio-time>*:*:*</f>" word. * may be any integer. I used find . -type f -exec grep -H '<f id=audio-time>.:.</f>' {} \; command to get. but i am not able to find the correct values. Any... (2 Replies)
Discussion started by: ananthi_ku
2 Replies

9. Shell Programming and Scripting

help for search or grep in a file

i have a file like <fruits> <red>redcolor<\red> <banana>yellow color and it is<\banana> </fruits> i want to search for a word in a file data between the tags i mean searching should be done in redcolcor, yellow color and it is (2 Replies)
Discussion started by: pvr_satya
2 Replies

10. UNIX for Dummies Questions & Answers

grep for a search string

Hi, I want to grep one file for a search string and get the next 10 lines after the search string. for eg,in file tnsnames.ora,i have 100 entries.i want to search for one string and get the entry for that db. please help how to acheive this using awk or sed? Thanks. (11 Replies)
Discussion started by: raga
11 Replies
Login or Register to Ask a Question