Removing new line after a particular text via bash/awk/sed/perl

前端 未结 8 1039
迷失自我
迷失自我 2021-01-02 00:22

I would like to remove all the newline character that occurs after a partiular string and replace it with a tab space. Say for instance my sample.txt is as follows



        
8条回答
  •  粉色の甜心
    2021-01-02 00:30

    This might work for you:

    echo -e "foo\nbar bar bar bar some text"| sed '/foo$/{N;s/\n/\t/}'
    foo     bar bar bar bar some text
    

    Actually:

    echo -e "foo\nbar bar bar bar some text"| sed '/foo$/N;s/\n/\t/'
    foo     bar bar bar bar some text
    

    The latter solution is less efficient but not by much!

提交回复
热议问题