Useful Shell Trick

August 6, 2009 at 10:40 pm | In Uncategorized | Leave a Comment

Sometimes, when doing a bunch of data munging in the shell, I want to pass the contents of a file through a shell pipeline, and then directly out into the file again. Unfortunately, doing this the naive way will obliterate the file’s contents.

So a while back, I saw a neat little utility called “sponge” which simply buffered data until it ended, and then output it. While useful, this wasn’t a standard Unix tool, so I couldn’t very well rely on having it available.

Well today, after literally minutes of searching, I have found a command that seems to work just as well:

tail -n +0

It outputs all lines in the input, beginning with line zero. Due, I suppose, to the way tail is implemented, it buffers all input before outputting anything.

Not exactly groundbreaking or anything, but a useful little trick to know when playing around in the shell.

No Comments Yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.