Insert lines in a file starting from a specific line

后端 未结 4 760
生来不讨喜
生来不讨喜 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:56

    sed is your friend:

    :~$ cat text.txt 
    foo
    bar
    baz
    ~$ 
    
    ~$ sed '/^bar/\na this is the new line/' text.txt > new_text.txt
    ~$ cat new_text.txt 
    foo
    bar
    this is the new line
    baz
    ~$ 
    

提交回复
热议问题