I need to add a line of text after each occurence of a pattern. I need this:pattern1pattern2To look like thispattern1pattern2new line data hereThe 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:pattern1pattern2 { text; };to thispattern1pattern2 { 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. 
Sed or AWK: Add line after each ocurrance of pattern between a range of line numbers
text processing;sed;awk
You can do this with vim!vim file.txt -c 226,2858g/pattern2/normal onew line data here -c wqYou can also do this interactively by doing this:vim file.txt:226,2858g/pattern2/normal onew line data here:wqWhich is the way I would prefer to do it, but I would understand if you prefer the first, being unfamiliar with vim.The way both of these work is by calling vim's :global command:                        *:g* *:global* *E147* *E148*:[range]g[lobal]/{pattern}/[cmd]            Execute the Ex command [cmd] (default :p) on the            lines within [range] where {pattern} matches.In this case, the range is lines 226-2858, the pattern is pattern2, and the ex command is normal onew line data hereWhat this does is it calls normal which means Enter the following keys as if I had typed them. Typing the 'o' key (o)pens a new line below the current one, and enters insert mode. Then, while in insert mode, the text new line data here is inserted into the file. The next command -c wq is just (w)rite and (q)uit.If your pattern uses regex, you should probably read through this wonderful page to help you troubleshoot if the pattern is matching correctly.