grep stands for “global regular expression print”.
Grep searches lines of a file that match a regular expression pattern and returns them.
It is by default case sensitive.
grep -Rl term /directory
searches all files in a directory and outputs only filenames with matched results.
grep -i searchTermRegularExpression my/Path/File/RegularExpressionNameFile
where:
Same Line Same Line
> New Line
Same Line 2 Same Line 2
Different Line | Different Line :)
cat diff.txt | grep '[\>\|]'
> New Line
Different Line | Different Line :)
See also egrep. Example: select the line that have user = ou group =
cat /etc/php-fpm.d/www.conf | egrep 'user =|group ='
user = www-data
group = www-data
grep -R SearchPattern /myPath/ToADir
find . -type f -exec grep -l "word"
with Linux - find command
$ ps -ef | grep nqsserver
oracle 4087 4018 0 13:19 pts/0 00:00:00 grep nqsserver
oracle 23915 20779 0 Mar05 ? 00:06:28 nqsserver -quiet
$ ps -ef | grep nqsserver | grep -v grep
oracle 23915 20779 0 Mar05 ? 00:06:28 nqsserver -quiet
$ ps -ef | grep [n]qsserver
oracle 23915 20779 0 Mar05 ? 00:06:28 nqsserver -quiet
grep pattern .*
Example
grep LD_LIBRARY_PATH .*
.bash_history:echo $LD_LIBRARY_PATH
.bash_profile: export LD_LIBRARY_PATH=${TT_HOME}/lib:${TT_HOME}/ttoracle_home/instantclient_11_2:${LD_LIBRARY_PATH}
grep -iE 'first|second'
cat myFile | grep -v 'jar'
grep -r -i -L --include "*.ini" "encrypt=true" .
ls | { IFS= read line1; echo $line1; grep fileName }
If the header has two lines
command | { IFS= read line1; read line2; echo $line1; echo $line2; grep pattern }