inserting text into a specific line

前端 未结 3 1524
北海茫月
北海茫月 2021-02-06 00:00

I\'ve got a text file, and using Bash I wish to insert text into into a specific line.

Text to be inserted for example is !comment: http://www.test.com into

3条回答
  •  臣服心动
    2021-02-06 00:45

    Using man 1 ed (which reads entire file into memory and performs in-place file editing without previous backup):

    # cf. http://wiki.bash-hackers.org/doku.php?id=howto:edit-ed
    line='!comment: http://www.test.com'
    #printf '%s\n' H '/!eeee/i' "$line" . wq | ed -s file
    printf '%s\n' H 5i "$line" . wq | ed -s file
    

提交回复
热议问题