LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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: 61
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: Lower Rhine region, Germany
Distribution: Slackware64 14.2 and current, SlackwareARM current
Posts: 1,645

Rep: Reputation: 146Reputation: 146
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
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:31 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
Open Source Consulting | Domain Registration