Similar approach to @gniourf_gniourf answer, but using ex
:
sudo ex +"r in.txt" -cwq out.txt
which is equivalent to vi
/vim
Ex-mode (-e
).
This in-place edit example is simple, safe and convenient approach, because it doesn't use any shell piping, FIFOs or shell within the shell workarounds.
To boost performance for scripting purposes, consider using silence mode (-s
).