It Seemed Like a Good Idea at the Time Coding, Mostly

6Aug/090

Useful Shell Trick

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.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.