Hi all,
This is my first post, so please go easy if I broke some rules. Not accustomed to posting in forums...
I'm looking for help on pattern matching within a multiline block and looking to highlight blocks/block-ids that do NOT contain a particular pattern.
For example an input file might contain the following:
fruit APPLE
blah1
PATTERN
blah2
fruitend
fruit ORANGE
blah1
blah2
blah3
fruitend
fruit KIWI
PATTERN
blah1
blah2
fruitend
In the above case, I would like the block of ORANGE or the keyword ORANGE printed, since the recognized pattern was not found.
I've been playing around with this for a while with no desired results found!!
sed -n '
/fruit /,/fruitend/ {H;g;s/\n//g;}
/PATTERN/ !p;
/fruit /,/fruitend/ !h;
'
Those results are the closest I can get to what I really want of:
fruit ORANGE
being the only listed output.
I figured out another way to do it, but was hoping to do it in one sed. I figured out if I pipe it through another sed statement like this:
<PREVIOUS OUTPUT> | sed -n 's/fruit \([A-Z]*\).*fruitend/\1/p'
That will print ORANGE only.