I have a file that has multiple similar patterns, each delimited by unique headers on preceding lines.
I would like to match/replace the pattern string only after header3 in this example:
header1
a
b
pattern
c
header2
a
b
c
d
pattern
header3
a
pattern
b
c
d
In my actual file, there may be any number of header strings, and any number of lines in between. So, the number of lines before or after the header3 match cannot be defined.
(Additionally, this machine does not have the gnu sed binary available, so this is not an option that can be used.)
I found an answer to my own question using an address range:
sed -i -r '/header3/,/pattern/ s|pattern|replacement|' filename
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With