LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 12-02-2005, 08:52 PM   #1
lucastic
Member
 
Registered: Aug 2003
Location: Oz
Distribution: Gentoo - Debian
Posts: 202

Rep: Reputation: 30
grep for multiple patterns????


Hi All,

This has bothered me now for a while now. How on earth do you get grep to search and display files that have multiple patterns present. Eg:

greptest.txt:

one
two
three
four
five

I want to search this file so that if 'one' and 'two' are present in the same file tell me the filename.

so if A and B then show C

NOT

if A then show C and if B then show C

This seems like it would be simple but I cannot find the answer and everything I try just matches the files with one pattern at a time!!

like when using

$grep -e one -e two -o *

fgrep seems to do the same thing.

What have I missed??
 
Old 12-02-2005, 10:37 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
Maybe something like this example in file.txt

cat file.txt
now is the time
for all good men to come to
the aid of their country
this is the time to come here
Code:
grep "time" < file.txt | grep "come"
this is the time to come here
 
Old 12-03-2005, 02:40 AM   #3
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Ruhr Area, Germany
Distribution: Slackware64 14.0
Posts: 1,524

Rep: Reputation: 94
Take a look at the following post and the whole thread -- above my own post there is another solution from theYinYeti I didn't test.
http://www.linuxquestions.org/questi...51#post1969751
 
Old 08-06-2010, 05:56 PM   #4
paulcontr
LQ Newbie
 
Registered: Aug 2010
Posts: 2

Rep: Reputation: 0
grep multiple patterns in the file

grep -li "pattern-1" `grep -li "pattern-2" *`
 
Old 08-06-2010, 06:07 PM   #5
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Hi paulcontr,

Welcome to LQ! Thanks for that update, but this thread is just short of 5 years old. Please note the date of the thread before posting, rather than resurrect a long-dead zombie-thread.

Cheers
 
0 members found this post helpful.
  


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
grep multiple strings GEEXTER Linux - General 7 12-06-2013 09:56 PM
linux find to find files with multiple patterns subu_s Programming 6 12-15-2010 12:15 AM
Remembering patterns and printing only those patterns using sed bernie82 Programming 5 05-26-2005 05:18 PM
Using grep to change multiple files zwyrbla Linux - General 5 01-11-2005 02:14 PM
multiline grep result > multiple variable? mikshaw Linux - Software 5 12-25-2003 10:13 PM


All times are GMT -5. The time now is 01:09 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration