Gostaria de saber se o pequeno sponge
utilitário de uso geral ("absorva a entrada padrão e escreva para um file ") de moreutils será útil neste caso e se seguirá o symlink.
O autor descreve sponge
like this :
It addresses the problem of editing files in-place with Unix tools, namely that if you just redirect output to the file you're trying to edit then the redirection takes effect (clobbering the contents of the file) before the first command in the pipeline gets round to reading from the file. Switches like
sed -i
andperl -i
work around this, but not every command you might want to use in a pipeline has such an option, and you can't use that approach with multiple-command pipelines anyway.I normally use sponge a bit like this:
sed '...' file | grep '...' | sponge file