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

前端 未结 8 974
迷失自我
迷失自我 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:40
    perl -pe 's/foo\n/foo\t/g' temp2.txt
    

    below is the test.

    243> cat temp2.txt 
    foo
    bar bar bar bar some text 
    pearl[ncm_o12.2_int_x86.@2].244> perl -pe 's/foo\n/foo\t/g' temp2.txt
    foo     bar bar bar bar some text 
    
    0 讨论(0)
  • 2021-01-02 00:41

    In awk:

    awk '/foo$/ { printf("%s\t", $0); next } 1'
    
    0 讨论(0)
提交回复
热议问题