Solved

Grep with AND relation

Posted on 2004-04-13
2
340 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

Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

785 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