Text substitution (reading from file and saving to the same file) on linux with sed
On Linux, sed -i
is the way to go. sed
isn't actually designed for in-place editing, though; historically, it's a filter, a program which edits a stream of data in a pipeline, and for this usage you would need to write to a temporary file and then rename it.
The reason you get an empty file is that the shell opens (and truncates) the file before running the command.