grep recursively in a directory


 
Thread Tools Search this Thread
Operating Systems Solaris grep recursively in a directory
# 1  
Old 03-24-2010
grep recursively in a directory

Hi,

how to grep recursively in a directory on Solaris OS.
grep -r throws an error that -r is an invalid option.

Please tell me if you have any solution.

Regards,
Jeevan.

ps.
I searched this forum for solution, but could not find anything useful.
# 2  
Old 03-24-2010
grep can not be recursively executed.

use

Code:
find /yourpath/  -type f -exec grep -l pattern {} \;

# 3  
Old 03-24-2010
Quote:
Originally Posted by jredx
grep -r throws an error that -r is an invalid option.
This is a Gnu grep extension.

If you have Solaris 10, Gnu grep might be already installed in /usr/sfw/bin/ggrep.

If you have an OpenSolaris based distribution, it should be in /usr/gnu/bin/grep.
# 4  
Old 03-24-2010
I'd strongly recommend using GNU grep. If that's simply not possible, see How can I recursively grep through sub-directories?
# 5  
Old 03-24-2010
If for some reason Gnu grep is not available on your OS, a simple and efficient alternative would be:

Code:
find /yourpath -type f -exec grep -l pattern /dev/null {} +

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy files recursively to one single directory

I need to copy a complete directory structure into a new location. But I want to have all files copied into one directory and leave out the directory structure. So all files must be placed in one directory. (4 Replies)
Discussion started by: ReneVL
4 Replies

2. Shell Programming and Scripting

Recursively grep for a pattern and print that whole word

Hello Forum Members, I am trying to write a script for a requirement where i have to recursively search for a pattern and replace it with the new string in run time from user inputs grep -ohr "]*.xyz.com]*" $HOME/source/group/ | sort | uniq > $HOME/output.txt while read -r -u9 line; ... (4 Replies)
Discussion started by: raokl
4 Replies

3. Shell Programming and Scripting

Find Large Files Recursively From Specific Directory

Hi. I found many scripts in the web of achieving this. But I like to use this one find /EDWH-DMT03 -xdev -size +10000 -exec ls -la {} \;|sort -n -k 5 > LARGE.rst But the problem is, why it still list out files with 89 bytes as the output? Is there anything wrong with the command? My... (7 Replies)
Discussion started by: aimy
7 Replies

4. Shell Programming and Scripting

How to recursively copy directory only for recent files?

I love the -newerct flag for the Cygwin find command on windows. Can I use "/usr/bin/find . -newerct '3 hours ago'" to conditionally copy a directory tree so that only the files in the directory tree that are younger than 3 hours are copied to my destination directory such that the directory... (4 Replies)
Discussion started by: siegfried
4 Replies

5. Shell Programming and Scripting

Recursively cat files in a directory with filename printed first.

I want to recursively cat the content of files in a directory e.g. find /etc -type f -exec cat {} \; But I want it to print the file name first and then the content. For example let's say /etc/statetab and /etc/colord.conf will be printed first then I want the output to look something like; ... (6 Replies)
Discussion started by: lewk
6 Replies

6. Shell Programming and Scripting

How to recursively search for a list of keywords in a given directory?

Hi all, how to recursively search for a list of keywords in a given directory?? for example: suppose i have kept all the keywords in a file called "procnamelist" (in separate line) and i have to search recursively in a directory called "target/dir" if i am not doing recursive search then... (4 Replies)
Discussion started by: neelmani
4 Replies

7. Shell Programming and Scripting

Need to find recursively all shell script in the /xyz directory

Pls. advise how to find or used grep recursively all shell script files. Some files doesnt have a .sh or .ksh extension name. find / -name "*" |xargs grep bin |grep sh ?? TIA (1 Reply)
Discussion started by: budz26
1 Replies

8. Shell Programming and Scripting

recursively Grep particular words among lines from a file

dear experts, Could you please help me to write a command/script to find follwing: from the log file i want to grep "resCode89270200100001552311" after that only "<resultCode>40614</resultCode>" it will be like that: resCode89270200100001552311 <resultCode>40614</resultCode> ... (7 Replies)
Discussion started by: thepurple
7 Replies

9. Shell Programming and Scripting

delete files recursively in the specified directory

I have to write a shell script which can delete all the files and directories recursively inside the specified directory but should not delete the specified directory. Please some body help me in writing the script. (3 Replies)
Discussion started by: deepthi.s
3 Replies

10. Shell Programming and Scripting

finding difference between 2 directory recursively

Hi, i'm trying to compare two directories in Unix. I need a recursive search ie my shell script should also compare common files in those two directory and so on... any clues.. ?? (2 Replies)
Discussion started by: yayati
2 Replies
Login or Register to Ask a Question