Search This Blog

AND OR NOT operators for grep

grep OR

  • use '\|'
    grep 'pattern1\|pattern2' file
  • use -E
    grep -E 'pattern1|pattern2' file
  • use -e
    grep -e pattern1 -e pattern2 file



grep AND

  • use pattern1.*pattern2
    grep -E 'pattern1.*pattern2|pattern2.*pattern1' file
  • use multiple (piped) grep commands
    grep pattern1 file | grep pattern2



grep NOT (invert) option

  • use -v option
    grep -v pattern file



see also

No comments:

Post a Comment