Thursday, June 5, 2014

'or'-ing terms with bash and grep

Needing to search for lines in a group of files having either of the supplied terms.

grep -e foo -e bar *.txt
With a more complete context:

  for file in $(ls aaa.txt bbb.txt)
  do
    echo ""
    echo $file
    echo "======================="
    cat $file | grep -e "^foo" -e "^bar"
  done
http://unix.stackexchange.com/questions/37313/how-do-i-grep-for-multiple-patterns

No comments:

Post a Comment