LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find two different in a file (https://www.linuxquestions.org/questions/linux-newbie-8/find-two-different-in-a-file-662914/)

ust 08-15-2008 01:33 AM

find two different in a file
 
I want to find all line that have the word "test" & "error" .

I know "cat myfile |grep test" can show the line with the word test , if I also want to show the line with the word "error" , what can i do ? thx


ps. that means show the line that have the word "test" OR "error" , what can i do ? thx

matthewg42 08-15-2008 01:52 AM

Do you mean:
Quote:

Only lines which contain both "error" and "test"
or
Quote:

Lines which contain either "error" or "test"
?

ust 08-15-2008 03:08 AM

Quote:

Originally Posted by matthewg42 (Post 3248231)
Do you mean:

or

?


Lines which contain either "error" or "test"


thx

Vit77 08-15-2008 03:17 AM

cat myfile | grep -e test -e error

pwc101 08-15-2008 03:20 AM

Quote:

Originally Posted by Vit77 (Post 3248282)
cat myfile | grep -e test -e error

There's no need to cat a file into grep, grep is quite capable of reading files all on its own:
Code:

grep -e test -e error myfile

Vit77 08-15-2008 03:56 AM

Quote:

Originally Posted by pwc101 (Post 3248283)
There's no need to cat a file into grep, grep is quite capable of reading files all on its own:
Code:

grep -e test -e error myfile

Oh, sure! :)

osamaensyviswinkel 08-18-2008 04:47 AM

You can use egrep for a shorter command syntax - see the output of the file below, and then egrep.

[11:45][root@francoisvn]/home/francoisvn # cat myfile
qwdqwidjqd
we
1312
235235235

123

test

1233twefvwd

error
12test
34error

[11:45][root@francoisvn]/home/francoisvn # egrep 'test|error' myfile
test
error
12test
34error


All times are GMT -5. The time now is 03:07 PM.