Operating System - HP-UX
1834340 Members
1737 Online
110066 Solutions
New Discussion

grep Matching anything except pattern

 
SOLVED
Go to solution
Paul Sperry
Honored Contributor

grep Matching anything except pattern

Hi all,

I have a bunch of email lists that I need to find out which one have external addresses.
I have used grep to find file pattern matches but never to find ones that don't match. I did a man grep but didn't see any ideas. How can I use find/grep to to find all files that contain addresses other than @mydomain.com

TIA
Paul
6 REPLIES 6
spex
Honored Contributor
Solution

Re: grep Matching anything except pattern

Explore grep's '-v' option.
A. Clay Stephenson
Acclaimed Contributor

Re: grep Matching anything except pattern

When you did a "man grep", you didn't look hard enough. Use the -v option which lists all lines except those matching the pattern.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: grep Matching anything except pattern

Hi Paul:

The '-v' switch of 'grep' negates a match. That is, 'grep -v' finds everything that does NOT match:

Compare :

# grep local /etc/hosts

...with:

# grep -v local /etc/hosts

Regards!

...JRF...

Shrikant Lavhate
Esteemed Contributor

Re: grep Matching anything except pattern

Yes,
grep -v
will do the required.
Will it remain a personal, if I broadcast it here!
Paul Sperry
Honored Contributor

Re: grep Matching anything except pattern

Silly me I passed the -v option assuming it was as usual verbos. Thanks guys/gals your the best. Bunnies for all!!
Paul Sperry
Honored Contributor

Re: grep Matching anything except pattern

Thanks Again