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


  Search this Thread
Old 03-06-2009, 04:21 AM   #1
Senior Member
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 31
grep file

I have to find the file that contains the string "aaa" AND "bbb" ( have both string), I tried the below command but it only find OR condition , can advise what can i do ?

egrep -i -H "aaa|bbb" *

Old 03-06-2009, 04:38 AM   #2
Didier Spaier
LQ Addict
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-14.2.1 on Lenovo Thinkpad W520
Posts: 8,689

Rep: Reputation: Disabled
I do not know how to 'and' but I use a pipe:
grep -i "aaa" *|grep -i "bbb"

Last edited by Didier Spaier; 03-06-2009 at 05:24 AM. Reason: Missing word
Old 03-06-2009, 04:42 AM   #3
LQ Addict
Registered: Oct 2003
Location: Australia
Distribution: MX 17
Posts: 5,299

Rep: Reputation: Disabled
didier beat me to it but I use a simpler

ls | grep aaa | grep bbb
Old 03-06-2009, 05:11 AM   #4
Senior Member
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 31
thx reply ,

It works , if I want to find the that in any directory in my server , I tried the below script , it is not work , can advise what can i do ?
what is wrong in my script ? thx

#find . -type f -exec grep -i "aaa" {} |grep -i "bbb" \;

grep: ;: No such file or directory
find: missing argument to `-exec'
Old 03-06-2009, 05:33 AM   #5
Registered: Jul 2006
Distribution: Debian, Ubuntu, openSUSE, CentOS
Posts: 147

Rep: Reputation: 19
find . -type f -exec grep -i "aaa" {} + |grep -i "bbb"


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 for string in file after a certain part of the file B-Boy Programming 6 02-18-2009 08:49 AM
can't grep file ust Linux - Software 3 01-07-2008 07:03 AM
how to grep all users's certain file packets Linux - Newbie 5 01-03-2008 09:35 PM
How can I grep text from file? @ngelot Linux - Software 6 06-13-2007 05:44 AM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 05:56 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:39 PM.

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