Grep usage

From raju

Some favorite options

grep -inH --color

multiple words

To grep for files that contain any of multiple keywords:

$ grep --color -E "word1|word2|word3" *.txt

To grep for files that contain all multiple keywords:

$ grep -l word1 *.txt | xargs grep -l word2 | xargs grep -l word3

To grep for files that contain multiple words (without any order) in one line:

$ grep word1 *.txt | grep word2 | grep word3

To grep for files that contain multiple words in one line in a given order:

$ egrep '(word1.*word2.*word3)' *

Ref:- http://xmodulo.com/how-to-grep-multiple-terms-or-strings.html

grep and view

open all files containing a keyword

$ grep keyword *.pl -l | xargs gvim -p

Exclude .git directory from grep searches

Exclude lines with tab

    grep -vP "\t" database.tsv