Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 09: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, 11:37 PM   #2
Senior Member
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 58
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, 03:40 AM   #3
Senior Member
Registered: Jul 2004
Location: Lower Rhine region, Germany
Distribution: Slackware 14.1 (32 and 64 bit)
Posts: 1,539

Rep: Reputation: 101Reputation: 101
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, 06: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, 07:07 PM   #5
LQ 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.

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

All times are GMT -5. The time now is 03:14 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration