4 ms·
sed -e s/foo/bar/ | sponge filename https://joeyh.name/code/moreutils/ https://joeyh.name/code/moreutils/
by 101km 10y ago
sed -e s/foo/bar/ | sponge filename
https://joeyh.name/code/moreutils/ https://joeyh.name/code/moreutils/
- OskarS 10y agoYou can also use the -i flag of sed to edit a file in-place. It leaves a backup file with the original in case you messed up.
- Annatar 10y agoI explicitly wrote: GNU sed -i is an architectural violation of the idea of a stream editor, and it isn't available everywhere. precisely to preclude anyone from suggesting using GNU sed -i.
- Annatar 10y agosponge is found on GNU/Linux, but is not a UNIX standard; when writing shell programs one must never assume GNU/Linux, because, as my ed(1) example shows, it is completely unnecessary and makes the code unportable for no reason whatsoever. Also by relying on external tools, you have now forced your users down the dependency hell path.
- qwertyuiop924 10y agoAssume the environment you're writing scripts for. Most scripts need only be run on one machine, and thus one platform. Most that don't still run only on one platform. If you need a portable shell script, by all means write one, but that's rarely the case.
- Annatar 10y agoAssume you know how to write shell programs which work everywhere without modification; why would you make your program unportable on purpose?
- qwertyuiop924 10y agoIn some cases, it can significantly shorten and clarify the code. That's a Good Thing. Nobody wants to debug shell scripts.
- Annatar 10y agoThe clean / portable way is in my experience always simpler, or rather, more rudimentary than using unnecessary GNU/Linux-only commands and constructs, simply because the clean / portable methodology uses the lowest common denominator. If you know of, or have such a case, I would be really interested to see it, out of purely professional interest. Nobody wants to debug shell scripts. I want to debug shell scripts, because of all the debugging I've done over the years, shell script debugging is by far the quickest / easiest: DEBUG="${DEBUG:-false}" $DEBUG && set -x and one can see the machine state immediately. Best debugging experience by far.
- deleted 10y ago[deleted]