• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

Grep with AND relation

Hi:

I don't know if this is the right forum for this question, but please, help me:

I know this grep sintax to find lines with stringa OR stringb in a file:

grep -E "stringa|stringb" file

Is there a specific sintax when I need to find lines with stringa AND stringb?

Thanks.

Mario./
0
multisites
Asked:
multisites
1 Solution
 
jlevieCommented:
grep -e "stringa.*stringb" should work. That says to return a match if a line contains stringa, zero or more intervening characters, and stringb.
0
 
Karl Heinz KremerCommented:
This only finds stringa and stringb if they occur in this order. What I usually do is to pipe multiple greps together:

grep stringa file | grep stringb
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now