How can I just print the pattern blocks where I have DFW-YYYY... and ignore the others. My start Pattern is ### My Ending Pattern is ##
Also the line pattern DFW-YYYY can have multi [] brackets. it is not fixed. I need to match the exact/ partial string (which could involve [blah] brackets for the match.
I had seen the article where the whole pattern is brought into a buffer and only printed when end pattern is found. I am looking for an enhancement to that thought process that I print conditionally once I find the start and end pattern block. The article I am talking about is: How to print lines between two patterns, inclusive or exclusive (in sed, AWK or Perl)?
I have a file like:
xxx
xxx
###
xxx
zzz Problem Key: DFW-XXXXX [blah blah][blah blah][blah blah]
yyy
xxx
*##*
yyy
###
zzz
xxx
yyy
zzz Problem Key: DFW-YYYY [blah blah][blah blah]
*##*
xxx
xxx
zzz
yyy
###
xxx
zzz Problem Key: DFW-XXXXX [blah blah][blah blah][blah blah]
yyy
xxx
*##* ....
The pattern I was trying to enhance was:
awk 'flag{
if (/*##*/)
if (print_flag =1 )
{printf "%s", buf; flag=0; buf=""} /* only print if print_flag =1 */
else
{ flag=0; buf=""} /* ignore pattern */
else
buf = buf $0 ORS
/* peek into $0 and look for conditional pattern.
conditional pattern may have sq brackets like [] but not limited to one occurrence
I could avoid spl chars if I could look for multiple small strings within $0.
Like $0 ~ "x" and $0 ~ "y" and $0 ~ "z", this way spl. char matching can be avoided
but conditional pattern can still be matched*/
if ($0 ~ "conditional-pattern1" and $0 ~ "conditional-pattern2" and $0 !~ "conditional-pattern3")
print_flag=1
}
/###/ {flag=1}' <file-name>
But my if statements of looking into $0 value for condition and assigning/ checking print_flag is failing syntactically.
Any guidance on how this could be achieved.