[ILUGC] Re: How to delete all the lines only if it matches two different patterns

  • From: Balachandran Sivakumar <benignbala@xxxxxxxxx>
  • To: ilugc@xxxxxxxxxxxxx
  • Date: Thu, 17 Nov 2016 09:33:11 +0530

Hi Baskar

On Thu, Nov 17, 2016 at 9:15 AM, Baskar Selvaraj <baskar@xxxxxxxxxxxx> wrote:


Ex. Donal Trump and Hillary Clinton

Search engines did not help much here.  Any SED solution would be nice.


sed -e '/pattern1/{/pattern2/d;}' inputfile

will work. Also, there are options with awk/perl.


AWK: awk '!(/pattern1/ && /pattern2/)' inputfile

Perl: perl -ne 'next if (/pattern1/ && /pattern2/); print;' inputfile

With sed and perl, we have the added advantage of inplace editing.
With awk, only GNU awk has it (at least that's what I remember).
Thanks

-- 
Thank you
Balachandran Sivakumar
_____________________________________
ILUGC List: http://www.freelists.org/list/ilugc
ILUGC Web: http://ilugc.in/

Other related posts: