How do you grep multiple words in one line in Unix?

Hưng Thịnh

New member
How do you grep multiple words in one line in Unix?
Answer
How do I grep for multiple patterns?
  1. Use single quotes in the pattern: grep ‘pattern*’ file1 file2.
  2. Next use extended regular expressions: egrep ‘pattern1|pattern2’ *. py.
  3. Finally, try on older Unix shells/oses: grep -e pattern1 -e pattern2 *. pl.
  4. Another option to grep two strings: grep ‘word1|word2’ input.
 

Tìm kiếm

Back
Top