Insert multiple lines of text before specific line using Bash

后端 未结 9 1444
猫巷女王i
猫巷女王i 2020-12-16 03:01

I am trying to insert a few lines of text before a specific line, but keep getting sed errors when I try to add a new line character. My command looks like:



        
9条回答
  •  囚心锁ツ
    2020-12-16 03:33

    To be POSIX compliant and run in OS X, I used the following (single quoted line and empty line are for demonstration purposes):

    sed -i "" "/[pattern]/i\\
    line 1\\
    line 2\\
    \'line 3 with single quotes\`
    \\
    " 
    

提交回复
热议问题