I have next file:
G
H
A
B
C
D
N
Let's delete lines from A to D and we will get next output:
G
H
N
It's very easy to do with sed '/A/,/D/d
, but if my file don't have D, then output will be empty. I want if there isn't second pattern (D) do not delete anything and show full file.
Second question - how to delete lines between patterns and next line after (N)? Kind of sed '/A/,+1d
, but sed '/A/,/D/+1d
will not work.
There is no different for me to use sed, awk or python/bash scripts.