Most people won’t find this paticularly useful, but as I’m prone to forget things:
sed -e '/^$/d'
will delete blank newlines from whatever it’s input is.
It’s actually faster to do this:
tr -d ‘\n’
Quick demo for you:
$ time (cat *.txt | sed -e ‘/^$/d’ >> /dev/null)
real 0m0.016s user 0m0.018s sys 0m0.001s
$ time (cat *.txt | tr -d ‘\n’ >> /dev/null)
real 0m0.010s user 0m0.011s sys 0m0.001s
real 0m0.009s user 0m0.011s sys 0m0.001s
It should also leave a smaller memory footprint:
$ ls -lah `which tr` -r-xr-xr-x 1 root wheel 18K May 10 11:53 /usr/bin/tr $ ls -lah `which sed` -r-xr-xr-x 1 root wheel 33K May 10 11:53 /usr/bin/sed
Every byte counts
It’s actually faster to do this:
tr -d ‘\n’
Quick demo for you:
$ time (cat *.txt | sed -e ‘/^$/d’ >> /dev/null)
real 0m0.016s
user 0m0.018s
sys 0m0.001s
$ time (cat *.txt | sed -e ‘/^$/d’ >> /dev/null)
real 0m0.016s
user 0m0.018s
sys 0m0.001s
$ time (cat *.txt | tr -d ‘\n’ >> /dev/null)
real 0m0.010s
user 0m0.011s
sys 0m0.001s
$ time (cat *.txt | tr -d ‘\n’ >> /dev/null)
real 0m0.009s
user 0m0.011s
sys 0m0.001s
It should also leave a smaller memory footprint:
$ ls -lah `which tr`
-r-xr-xr-x 1 root wheel 18K May 10 11:53 /usr/bin/tr
$ ls -lah `which sed`
-r-xr-xr-x 1 root wheel 33K May 10 11:53 /usr/bin/sed
Every byte counts