osx - How to insert 4 newlines before pattern match with SED? -


How to enter 4 reclamation before pattern fairs

I can

  sed '/ patterntosearch4 / g' 1.txt & gt; 2.txt  

After each pattern to create a new file (2.txt) with a blank line.

But how to enter the first 4 blank lines? / P>

The Manpant SED did not seem to answer.

Any help is appreciated!

This can work for you (GNU sed):

  Sed '/ patterntosearch4 / i \\ n \ n \ n' file  

or if you want:

  sed -e '/ patterntosearch4 /! B '-e' g 'a' / / (. * \) \ (. \) / \ 2 \ 2 \ 2 \ 2 \ 1 / 'file  

As you < Using the code> g command, which joins a new line after the line with the pattern of the match, I had guessed that you had inserted a new line before the line with pattern matching.


Comments