On 2019-08-31 at 12:02, Jonas Smedegaard wrote: > Quoting The Wanderer (2019-08-31 14:39:56) > >> In practice, I'd either use this with 'sed -i [the above >> expression] filename' or (more likely) with 'cat filename | sed >> [the above expression] > newfilename'. > > While wandering(!) off of the original topic, there is also this: > > cat filename | sed [the above expression] | spong filename > > ...for writing back (potentially in later iteration) longer pipelines > back to same file.
Now *that* is interesting, and at least at a glance, solves a problem I've been nervous about many times in the past. For awareness by those who may not care to check the man page, or who (like me) didn't catch it on first doing so: sponge appears to soak up all input (which I think means "wait for EOF") before initiating output, so unlike redirecting back to the original filename, won't truncate it before the initial command has finished reading. There's also 'sponge -a', to replace >> instead of replacing >. > sponge is part of Debian package moreutils. I have that installed, but apparently never looked at this particular utility. I may have to do a run-through of everything in there, if this is any example of how useful they can be. -- The Wanderer The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man. -- George Bernard Shaw
signature.asc
Description: OpenPGP digital signature