LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-15-2008, 02:33 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
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
 
Old 08-15-2008, 02:52 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Do you mean:
Quote:
Only lines which contain both "error" and "test"
or
Quote:
Lines which contain either "error" or "test"
?
 
Old 08-15-2008, 04:08 AM   #3
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by matthewg42 View Post
Do you mean:

or

?

Lines which contain either "error" or "test"


thx
 
Old 08-15-2008, 04:17 AM   #4
Vit77
Member
 
Registered: Jun 2008
Location: Toronto, Canada
Distribution: SuSE, RHEL, Mageia
Posts: 132

Rep: Reputation: 17
cat myfile | grep -e test -e error
 
Old 08-15-2008, 04:20 AM   #5
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by Vit77 View Post
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
 
Old 08-15-2008, 04:56 AM   #6
Vit77
Member
 
Registered: Jun 2008
Location: Toronto, Canada
Distribution: SuSE, RHEL, Mageia
Posts: 132

Rep: Reputation: 17
Quote:
Originally Posted by pwc101 View Post
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!
 
Old 08-18-2008, 05:47 AM   #7
osamaensyviswinkel
LQ Newbie
 
Registered: Sep 2007
Location: Stellenbosch, South Africa
Distribution: Ubuntu 12.10 at home, Mac OS X on laptop
Posts: 20

Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to find if a matching file exist from a list of possible file names wit_273 Linux - General 5 10-25-2007 10:47 AM
how to find time of file creation of a given file??? raklo Linux - General 4 08-13-2007 06:28 AM
Linker problem: can't find a file, but the file exists atlep Programming 5 08-16-2004 07:15 AM
Find File broken, need search utility, where does WineX install, KDE file roller? Ohmn Mandriva 6 07-05-2004 11:34 PM
where can I find grammar file and lex file of GNU c ? thinks Huiming Linux - Software 1 06-11-2004 08:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration