[wellylug] Some help with grep

michael at diaspora.gen.nz michael at diaspora.gen.nz
Sun Jun 20 12:07:58 NZST 2004


Jamie Dobbs writes:
>Is there any way with grep that I can search for certain instances of
>a string (in this case an email domain) but not include a certain
>address.
>
>ie. I want to find all occurances of @domain.co.nz in the file but have it ign
ore
>any instances of this_address at domain.co.nz

Use perl if you want just one command, instead of grep and grep -V:

    perl -ne 'print if /@domain.co.nz/&&!/this_address at domain.co.nz/' < file

or, being really fancy and unreadable, and only works with Perl 5.6
and above:

    perl -ne 'print if /(?<!this_address)@domain.co.nz/' < file

Michael.




More information about the wellylug mailing list