Link to home
Start Free TrialLog in
Avatar of oxygen_728
oxygen_728

asked on

Linux - Grep - How do I search for two terms at once?

I want to search for all files that contain both "password" and "_PUT"

How would i do this on a grep search?

Thanks

Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Hi oxygen_728,

On the same line or anywhere in the file?



Kent
Avatar of oxygen_728
oxygen_728

ASKER

I'd prefer on the same line,

but i'd like to know how to do it in the same file too

Thanks for your time
put the different strings in a file e.g. myfile

string1
string2

then use grep -f myfile *
Omar, does that search for them on the same line?

Do I put quotes around my strings?

Does that search for both terms using an AND conjunction or an OR conjunction?

Thanks
no, this is an OR so either string1 or string2 or .....

if in the same line the use

string1*string2
Omar, I cannot seem to get that to work

can you provide a more detailed example?
also,you can do

grep string1 * | grep string2 | grep string3

I could not do it with string1*string2
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ghost, is there some way to alternatively check a file for both of those that don't necessarily occur on the same line?

Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
grep -l password `grep -l _PUT *`