-   Linux - Newbie (
-   -   logical operators in grep (

ahmedb72 12-14-2009 01:14 PM

logical operators in grep
How can I implement logical operators in grep? I checked the man info and couldn't figure it out.

For example, I'd like to display lines in file1.txt that contains word1 OR word2.

cat file1.txt | grep word1 OR word2

Thanks in advance.

SethsdadtheLinuxer 12-14-2009 02:30 PM

try the --regexp flag.

Tinkster 12-14-2009 02:43 PM

grep -E "word1|word2" file1.txt

No need to swing cats =}

ghostdog74 12-14-2009 08:55 PM

another tool you can use is awk,

awk '/WORD1|WORD2/' file

awk '/WORD1/&&/WORD2/' file

All times are GMT -5. The time now is 11:24 AM.