Insert multiple lines of text before specific line using Bash

后端 未结 9 1467
猫巷女王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:40

    This ll works from the first line.. For eg: If you want to insert from 3rd line of a file, replace "1i" to "3i".

    sed -i '1i line1'\\n'line2'\\n'line3' 1.txt 
    
    cat 1.txt
    
     line1
     line2
     line3
     Hai
    

提交回复
热议问题