[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 10:47:25 +0530

Hi Baskar,

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


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

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

Billion thanks.  btw, if I match for 3 patterns, how should I construct it.


    It is a little messy. Something like this:

sed -e '/pattern1/{b p2}; /somepattern/ {s/lower/UPPER/g}; :p2;
/pattern2/ { /pattern3/d;};' inputfile

should work. To explain,

1) If pattern1 matches, branch to label p2 (too lazy to type pattern2)
2) If some pattern matches, the block changes some string lower in
that line to UPPER.
3) In branch p2, if pattern2 matches, and inside the block, if
pattern3 matches as well, we delete.

But I guess awk/perl would be simpler than this. Thanks


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

Other related posts: