3

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
AWE
  • 4,045
  • 9
  • 33
  • 42

4 Answers4

4

to delete blank lines:

sed '/^[[:space:]]*$/d'
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
3

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'
coltox
  • 360
  • 3
  • 8
  • This is such an old question I have no idea where this mysterious file is today. – AWE Nov 16 '12 at 11:43
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'
Jeremy Stein
  • 19,171
  • 16
  • 68
  • 83
0

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)

Grzegorz Grzybek
  • 6,152
  • 3
  • 29
  • 42
  • 1. You can also use `grep -v '^$'` 2. How do you use `sed` command? With UNIX pipes? (`cat file | sed ...`)? Maybe you're piping standard error output instead of standard output? – Grzegorz Grzybek May 25 '12 at 17:21
  • Grep gave me the same result. I "sed 'blahblah' file > newfile". – AWE May 25 '12 at 22:43