sed insert line command OSX

前端 未结 7 2146
太阳男子
太阳男子 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:50

    Here's how to do it in one line syntax

    sed -i '' -e "2s/^//p; 2s/^.*/text to insert/" file
    
    • duplicate second line: 2s/^//p;

    • replace new line with your text: 2s/^.*/text to insert/

    0 讨论(0)
提交回复
热议问题