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: , ,

» Filed under General Life by Chris Ganderton at 21:47.

back to top

1 comment
to removing blank newlines using sed.

  1. leE

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

Subscribe to comments or TrackBack to removing blank newlines using sed.

Leave a comment







Credits and stuff

Copyright © [ 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