问题
I have a file like this:
2733617 3.00 3 3
2733617 E1b1 8.00 8 16
2733617 E1b1b1b 2.00 2 4
2733617 I1 294.00 296 590
2733617 I2 1.00 1 2
2733617 I2a1 2.00 2 4
sed '/^$/d'
does not work for me. Outfile looks just like infile. It should remove empty lines.
回答1:
Unfortunately the manual says that using ranges like [!-~]
is not safe. However, just printing the lines that containing printable characters using :print:
worked for me in the end:
sed -n '/[[:print:]]/p'
回答2:
Since there appear to be unknown non-printable characters in the "blank" lines, you could re-write your sed command to only display lines with printable characters in them:
sed -n '/[!-~]/p'
回答3:
to delete blank lines:
sed '/^[[:space:]]*$/d'
回答4:
You can also try:
sed -n '/^./p'
which prints only lines which have at least one char at the beginning of the line. (BTW sed '/^$/d'
works for me)
来源:https://stackoverflow.com/questions/10755692/cant-remove-empty-lines-with-sed-regex