I have a file with the following content. I am trying to extract the block with matching start and end patterns, in between I want to exclude the block which has a non-matching numeric id ( maybe a pattern ). Here other than [001] has to be excluded. 002 may not be known. So, I want the blocks only matching with [001].
File contains,
text [001] start
line 1
line 2
text [002] mid start
line 3
line 4
text [002] mid end
line 5
line 6
text [001] end
I need the block, with excluding nonmatching numeric id [002]'s block.
text [001] start
line 1
line 2
line 5
line 6
text [001] end
I couldn't get a clear clarification on the internet for this problem. Can anyone help with this, awk or sed solution?
To get the block with start and end pattern, I am trying with
awk '/[001]/ && /start/, /001/ && /end/' File