7 ms·
I'm a big fan of Joey Hess' moreutils - https://joeyh.name/code/moreutils/ https://joeyh.name/code/moreutils/ Examples: - sponge: read in all of stdin, then w
by alec 13y ago
I'm a big fan of Joey Hess' moreutils - https://joeyh.name/code/moreutils/ https://joeyh.name/code/moreutils/
Examples:
- sponge: read in all of stdin, then write to the given file. Great for pipelines: sed "s/root/toor/" /etc/passwd | grep -v joey | sponge /etc/passwd
- vipe: easily drop a $EDITOR instance in the middle of a pipe chain
- ts: timestamp all standard input; great for long-running output
- wging 13y agoHow is sponge different from > filename?
- tmhedberg 13y agoFor one thing, it allows your pipeline to both read from and write to the same file, as it defers the output until there is no more data to read from "upstream". For instance, this won't work (it truncates the file for writing before it is ever read): grep foo <some_file >some_file But this will have the intended effect: grep foo <some_file | sponge some_file
- loevborg 13y agoIt can be used where ">" does not work, e.g. when using sudo. So you can do echo data | sudo sponge /etc/a.file `tee` can be abused in a similar way, but it also prints the data to stdout, which is ugly.
- justincormack 13y agosed can edit in place though.
- kylek 13y agoindeed! sed -i -e 's/root/toor/' -e '/joey/d' /etc/passwd
- stevekemp 13y agoI hope my own collection of related tools is also useful? https://github.com/skx/sysadmin-util https://github.com/skx/sysadmin-util More focused on those a sysadmin might prefer than general-use, but contributions or updates are welcome.
- chipb 13y agoAlthough there's some real gems in there (I can't believe I never ran across vipe before!), its Debian package conflicts with the GNU parallel package: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=718816 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=718816 Quite annoying.