[ t h e f r a g g l e . c o m ]

technology, photography and anything else that springs to mind.

xen vcpu pinning defaults aren’t ideal »« TanTan flickr photo gallery broken after upgrade to Wordpress 2.3

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: , ,
, ,
February 17, 2008 at 9:47 pm
2 comments »
  • June 27, 2008 at 1:32 pmleE

    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 ;)

  • July 28, 2008 at 1:14 amJack Wallenberg

    Your are Great. And so is your site! Awesome content. Good job guys!

Leave a Reply or trackback