Remove empty lines in a text file via grep

后端 未结 11 1600
佛祖请我去吃肉
佛祖请我去吃肉 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:50

    Here is a solution that removes all lines that are either blank or contain only space characters:

    grep -v '^[[:space:]]*$' foo.txt
    

提交回复
热议问题