Sunday, February 17th, 2008
removing blank newlines using sed.
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.
Tags: geek, Linux, stufftechnology, photography and anything else that comes into the rambling mind of chris ganderton
Sunday, February 17th, 2008
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.
Tags: geek, Linux, stuffCopyright © [ t h e f r a g g l e . c o m ] | Powered by WP 2.3.1. | Tree by Headsetoptions and MandarinMusing a minimal theme based on HyperBallad Back to Content
on Friday, June 27th, 2008 at 1:32 pm:
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