Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-18-2009, 02:25 PM   #1
LQ Newbie
Registered: Jan 2009
Posts: 1

Rep: Reputation: 0
grep command for invert matching

Hi friends,

I m new to this forum , I hv a problem . In linux , for invert matching we use 'grep -v string'. If i have 2 or more than 2 sets of string, can I use only single 'grep' for invert matching. Currently I use following command:

grep -v string1 abc.txt| grep -v string2 abc.txt

Please help me
Old 01-18-2009, 02:49 PM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Welcome to LQ!!

egrep -v "$string1|$string2" filename
grep -e -v "$string1|$string2" filename

In this context, "|" is called the "alternation" operator---fancy way of saying "OR".
Old 04-01-2009, 08:25 AM   #3
Registered: Feb 2008
Posts: 32

Rep: Reputation: 15

You can also use the grep command like this as
grep -v -e "pattern1" -e "pattern2"

Last edited by Tinkster; 04-01-2009 at 10:59 AM. Reason: less traffic driving


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
Matching a domain with grep abefroman Programming 2 11-06-2008 03:07 AM
how to use grep to print just the matching expression and nothing else new_2_unix Linux - Newbie 5 01-07-2008 05:02 PM
Problem with grep matching to end of line icedown Linux - Newbie 12 09-23-2007 05:43 AM
pattern matching question - grep cbriscoejr Programming 1 02-09-2006 08:30 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:57 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration