Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 1200  / 1 Year ago, wed, march 22, 2023, 2:31:47

I can search for files which have a specific word by using grep



grep -l "word" /path


However what if I want to search for files which have "word 1" and "word 2" in a same line? I can use:



mkdir new;for i in * do;grep "word 1" $i > new/$i_new;done


then use



grep -l "word 2" /new


But I would like to have a one line command. Using



egrep -w -R 'word 1|word 2' /path


only search for lines have "word 1" OR "word 2".



What if I have "word 3", "word 4"?


More From » grep

 Answers
2

Use pipes to successively filter the lines, until you get what you want:
grep word1 /path | grep word2 | grep word3 | grep word4


[#24304] Friday, March 24, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rieency

Total Points: 299
Total Questions: 116
Total Answers: 111

Location: Wales
Member since Tue, Dec 14, 2021
2 Years ago
;