LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   logical operators in grep (https://www.linuxquestions.org/questions/linux-newbie-8/logical-operators-in-grep-775595/)

ahmedb72 12-14-2009 01:14 PM

logical operators in grep
 
Hi,
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,
ORing
Code:

awk '/WORD1|WORD2/' file
ANDing
Code:

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


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