LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   grep file (https://www.linuxquestions.org/questions/linux-newbie-8/grep-file-709572/)

ust 03-06-2009 03:21 AM

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

Didier Spaier 03-06-2009 03:38 AM

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

aus9 03-06-2009 03:42 AM

didier beat me to it but I use a simpler

ls | grep aaa | grep bbb

ust 03-06-2009 04:11 AM

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'

rizwanrafique 03-06-2009 04:33 AM

Code:

find . -type f -exec grep -i "aaa" {} + |grep -i "bbb"


All times are GMT -5. The time now is 02:46 AM.