5 grep tips

Image by Harshad Sharma
Image by Harshad Sharma

Here’s a few tips for using grep.
NOTE : Some of these will work with your version of grep, some may not. In Solaris there can be two or three different versions of grep available. If one of these doesn’t work for you, try reading the man page for your version.
1. Use a pipe to search for multiple items.
shell> grep -P 'text|name' file.txt
2. Use xargs to search in sub-directories.
shell> find . | xargs grep whatever
3. Search for a string starting with a uppercase or lower case s.
shell> grep [Ss]tring
4.  Remove the grep process from the output
shell> ps aux | grep '[p]erl'
5. Finding string with color highlighting
shell> grep --color='auto' -i error /var/log/messages