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

前端 未结 5 861
南方客
南方客 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 14:05

    Another possibility, e.g. if You don't have an empty hold register, could be:

    sed '/pattern/{p;s/.*//}' file
    

    Explanation:
    /pattern/{...} = apply sequence of commands, if line with pattern found,
    p = print the current line,
    ; = separator between commands,
    s/.*// = replace anything with nothing in the pattern register,
    then automatically print the empty pattern register as additional line)

提交回复
热议问题