LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: 30
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" *




Thx
 
Old 03-06-2009, 03:38 AM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-14.2 on Lenovo Thinkpad W520
Posts: 7,435

Rep: Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398
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 04:24 AM. Reason: Missing word
 
Old 03-06-2009, 03:42 AM   #3
aus9
LQ Guru
 
Registered: Oct 2003
Distribution: Fedora 25 Gnome (Wayland)
Posts: 5,132

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

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

Original Poster
Rep: Reputation: 30
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, 04:33 AM   #5
rizwanrafique
Member
 
Registered: Jul 2006
Distribution: Debian, Ubuntu, openSUSE, CentOS
Posts: 147

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


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


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