How can I do recursive grep on Solaris?
When I tried, I received this error:
-r: invalid option.
|
How can I do recursive grep on Solaris? When I tried, I received this error:
| ||||
|
feedback
|
This question came from our site for professional and enthusiast programmers.
|
Recursive grep on Solaris:
| |||||||||
feedback
|
|
| |||||
|
feedback
|
|
If you are lucky, you have gnu grep installed also. It will then be named "ggrep". | |||
|
feedback
|
|
-r option for grep works only with gnu grep. Solutions with xargs are good, but cause some problems - find | xargs grep will break on filenames with spaces, and besides - xargs is also gnu tool, so it might be not installed. As far as I know, the proper way to do it on solaris is:
Also, note that solaris (well, unix) grep doesn't have (for example) -E option, and you should use | |||
|
feedback
|
This will also work for filenames with spaces. Why /dev/null? Because each grep instance will inspect a single file at a time and therefore doesn't print the filename if it finds a match. That's fine if you are really grepping a single file only, but doesn't help if grep is repetitively called from find. The additional /dev/null serves as an extra dummy file to search so that grep will prepend the current filename when it prints the matching line. | |||||||
feedback
|