Insert lines in a file starting from a specific line

后端 未结 4 739
生来不讨喜
生来不讨喜 2020-12-23 01:54

I would like to insert lines into a file in bash starting from a specific line.

Each line is a string which is an element of an array

line[0]=\"foo\"         


        
4条回答
  •  暖寄归人
    2020-12-23 02:38

    Or anoter one example with the sed:

    echo -e "line 1\nline 2\nline 3\nline 4" > /tmp/test.py
    cat /tmp/test.py
    line 1
    line 2
    line 3
    line 4
    
    sed -i '2 a line 2.5' /tmp/test.py    # sed for inside of the file 'LINE_NUMBER append TEXT'
    cat /tmp/test.py
    line 1
    line 2
    line 2.5
    line 3
    line 4
    

提交回复
热议问题