Solved

Grep with AND relation

Posted on 2004-04-13
2
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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