sed replace empty line with character

前端 未结 5 1609
庸人自扰
庸人自扰 2021-01-15 02:31

How do you replace a blank line in a file with a certain character using sed?

I have used the following command but it still returns the original input:



        
5条回答
  •  借酒劲吻你
    2021-01-15 03:11

    Here is a way with awk. This wouldn't care if you have spaces or blank lines:

    awk '!NF{$0=">"}1' file
    

    NF stands for number of fields. Since blank lines or lines with just spaces have no fields, we use that to insert your text. 1 triggers the condition to be true and prints the line:

    Test:

    $ cat -vet file
    ACTCTATCATC$
          $
    CTACTATCTATCC$
    $
    CCATCATCTACTC$
           $
    

    $ are end of line markers

    $ awk '!NF{$0=">"}1' file
    ACTCTATCATC
    >
    CTACTATCTATCC
    >
    CCATCATCTACTC
    >
    

提交回复
热议问题