sed replace empty line with character

前端 未结 5 1607
庸人自扰
庸人自扰 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:09

    What's missing here is the escape character. This will work for you.

    sed 's/^$/\>/g' filename
    

    And if you need to delete the empty lines and print others, Try

    sed '/^$/d' filename
    

提交回复
热议问题