Remove newline depending on the format of the next line

前端 未结 4 886
抹茶落季
抹茶落季 2021-01-14 08:34

I have a special file with this kind of format :

title1
_1 texthere
title2
_2 texthere

I would like all newlines starting with \"_\" to be

4条回答
  •  情歌与酒
    2021-01-14 09:09

    This might work for you (GNU sed):

    sed ':a;N;s/\n_/ /;ta;P;D' file
    

    This avoids slurping the file into memory.

    or:

    sed -e ':a' -e 'N' -e 's/\n_/ /' -e 'ta' -e 'P' -e 'D' file
    

提交回复
热议问题