A few weeks I wrote about a tool, which helps you easily prepend to a file. I submitted prepend to moreutils and Joey was kind enough to point out this could be done with `sponge’.  sponge reads standard input and when done, writes it to a file:

Probably the most general purpose tool in moreutils so far is sponge(1), which lets you do things like this:

% sed "s/root/toor/" /etc/passwd | grep -v joey | sponge /etc/passwd

Two days ago Joey released version 0.29 of moreutils including a patch by yours truly (with much help from Joey).

sponge: Handle large data sizes by using a temp file rather than by  consuming arbitrary amounts of memory. Patch by Brock Noland. version 0.29 changelog

Also, on a non-command line note, I found a video on Joey’s site which I thought was pretty cool, Joey Learns to Fly.

6 Responses to “prepend to a file with sponge from moreutils”

  1. New command: prepend Says:

    [...] The code that led me to create this project was a command I am calling prepend 1.1. (UPDATE: See this post on sponge as its a better general case [...]

  2. The best in command line xml: XMLStarlet Says:

    [...] prepend to a file with sponge from moreutils [...]

  3. Andreas F. Geissbuehler Says:

    you talk about ‘sponge’, curious, I fail to find a http://bashcurescancer.com/man/cmd/sponge or an entry in the list of command names beginning with ‘S’.

  4. Светлана Says:

    Хм

  5. Kristina Says:

    Хм

  6. William Ghelfi Says:

    I found this site yesterday, and I’m really enjoying the reading.

    But I really can’t figure out how to prepend a line in file using sponge…

    Tried
    echo “The file really starts here” | sponge sponge_me
    but it ended up with that single line in a file previously containing 4 lines…

Leave a Reply

If Wordpress eats your comment (shell output, loops, ex..) brock (at) gmail dot com.