sed insert line command OSX

前端 未结 7 2150
太阳男子
太阳男子 2020-12-16 14:02

I\'m trying to insert text to the third line in a file using sed, and the syntax I\'ve found on other forums is:

sed -i \'\' \"3i\\ text to insert\" file
         


        
7条回答
  •  Happy的楠姐
    2020-12-16 14:30

    I've found that I have to insert a \ at the end of the line to be inserted, otherwise it concatenates it at the beginning of the original line. So, if I want to insert a new third line,...

    sed -i '' '3i\
    New line to be inserted.\
    ' file

提交回复
热议问题