I've been trying to find a way to filter a line that has the word "lemon" and "rice" in it. I know how to find "lemon" or "rice" but not the two of them. They don't need to be next to the other, just one the same line of text.
Ubuntu – Grep searching two words in a line
greptext processing
Best Answer
"Both on the same line" means "'rice' followed by random characters followed by 'lemon' or the other way around".
In regex that is
rice.*lemon
orlemon.*rice
. You can combine that using a|
:If you want to use normal regex instead of extended ones (
-E
) you need a backslash before the|
:For more words that quickly gets a bit lengthy and it's usually easier to use multiple calls of
grep
, for example: