How do I add a line of text to the middle of a file using bash?

前端 未结 6 999
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 22:28

I\'m trying to add a line of text to the middle of a text file in a bash script. Specifically I\'m trying add a nameserver to my /etc/resolv.conf file. As it stands, resol

6条回答
  •  星月不相逢
    2020-12-02 23:12

    How about something like:

    sed -e ':a;N;$!ba;s/nameserver/nameserver 127.0.0.1\nnameserver/' /etc/resolv.conf
    

    (similar to this: sed: Find pattern over two lines, not replace after that pattern)

提交回复
热议问题