Remove empty lines in a text file via grep

后端 未结 11 1652
佛祖请我去吃肉
佛祖请我去吃肉 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-13 00:02

    Try ex-way:

    ex -s +'v/\S/d' -cwq test.txt
    

    For multiple files (edit in-place):

    ex -s +'bufdo!v/\S/d' -cxa *.txt
    

    Without modifying the file (just print on the standard output):

    cat test.txt | ex -s +'v/\S/d' +%p +q! /dev/stdin
    

提交回复
热议问题