Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 12-02-2005, 08:52 PM   #1
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:



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


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
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
grep "time" < file.txt | grep "come"
this is the time to come here
Old 12-03-2005, 02:40 AM   #3
Senior Member
Registered: Jul 2004
Location: Lower Rhine region, Germany
Distribution: Slackware64 14.2 and current, SlackwareARM current
Posts: 1,648

Rep: Reputation: 148Reputation: 148
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.
Old 08-06-2010, 05:56 PM   #4
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
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.

0 members found this post helpful.


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 > Forums > Linux Forums > Linux - Software

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

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