Remove empty lines in a text file via grep

后端 未结 11 1669
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-12 23:17

FILE:

hello

world

foo

bar

How can I remove all the empty new lines in this FILE?

Output of command:

11条回答
  •  生来不讨喜
    2020-12-12 23:52

    grep '^..' my_file

    example

    THIS
    
    IS
    
    THE
    
    FILE
    
    EOF_MYFILE
    

    it gives as output only lines with at least 2 characters.

    THIS
    IS
    THE
    FILE
    EOF_MYFILE
    

    See also the results with grep '^' my_file outputs

    THIS
    
    IS
    
    THE
    
    FILE
    
    EOF_MYFILE
    

    and also with grep '^.' my_file outputs

    THIS
    IS
    THE
    FILE
    EOF_MYFILE
    

提交回复
热议问题