Monday, June 10, 2013

How to grep recursively in Solaris?

In Solaris, Solaris grep will not provide recursive option -r to search a pattern recursively. But solaris provides another command called ggrep to search recursively. But ggrep location is normally not included in the PATH variable.

[vjsujay@cheetah:/home/vjsujay]$which ggrep
no ggrep in /usr/bin /bin /usr/sbin /sbin /usr/local/bin

[vjsujay@cheetah:/home/vjsujay]$ls -l /usr/sfw/bin/ggrep
-r-xr-xr-x   3 root     bin       125664 Jan 23  2005 /usr/sfw/bin/ggrep

Example for recursive grep using ggrep in Solaris:

[vjsujay@cheetah:/home/vjsujay/sp]$ /usr/sfw/bin/ggrep -R 'apple' *
file3.txt:apple orange