I need to add a line of text after each occurence of a pattern. I need this:
pattern1
pattern2
To look like this
pattern1
pattern2
new line data here
The new line data will always come after pattern2. pattern2 will always be the same and I have well over 100 occurences of patter2. And I only want to do this when I seen pattern 2 between lines 226 and 2858. I would like to do an in-place modification and do all this without wiping out anything else in the file. (already did that once while testing, don't want to do it again)
UPDATE - I need to be more precise as my patterns contain special characters. So I'm actually changing this:
pattern1
pattern2 { text; };
to this
pattern1
pattern2 { text; };
new data { text; text; text; };
So matching on pattern 2 that contains special characters and adding the new data line with the special characters. Should have disclosed that before. Sorry for any confusion.
pattern
come into play?sed
orawk
, or would using a different tool be acceptable?