How do I insert a newline/linebreak after a line using sed

前端 未结 5 870
南方客
南方客 2020-12-28 13:43

It took me a while to figure out how to do this, so posting in case anyone else is looking for the same.

5条回答
  •  青春惊慌失措
    2020-12-28 13:57

    sed '/pattern/a\\r' file name 
    

    It will add a return after the pattern while g will replace the pattern with a blank line.

    If a new line (blank) has to be added at end of the file use this:

    sed '$a\\r' file name
    

提交回复
热议问题