Saturday, October 13, 2012

Linux command: grep string1 OR/AND string2 in a file


To search for lines containing string1 or string2 in a file (e.g. my_file.txt):
   $ grep -E string1\|string2 my_file.txt

To search for lines not containing string1 or string2 in the file:
   $ grep -v -E string1\|string2 my_file.txt

To search for lines containing both string1 and string2 in the file:
   $ grep -e string1 -e string2 my_file.txt

To search for lines not containing both string1 or string2 in the file:
   $ grep -v -e string1 -e string2 my_file.txt

No comments:

 
Get This <