sed insert line command OSX

前端 未结 7 2159
太阳男子
太阳男子 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条回答
  •  情话喂你
    2020-12-16 14:36

    A one-liner for OSX employing ANSI-C quoting:

    sed -i '' '3i\'$'\n''text to insert' file
    

    Adapted from https://stackoverflow.com/a/24299845/901597

提交回复
热议问题