Solved

Grep with AND relation

Posted on 2004-04-13
2
341 Views
Last Modified: 2013-12-15
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
Comment
Question by:multisites
2 Comments
 
LVL 40

Accepted Solution

by:
jlevie earned 50 total points
ID: 10817256
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
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10817766
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

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question