Parameter | Details |
---|---|
extension | Save a backup file with the specified extension, or no backup file when extension is a zero-length string. |
In-place editing is a common but non-standard extension present in the majority of recent systems.
From a BSD sed
manual
(a section like this appears in all current BSD sed
manuals, and those of their derivatives)
It is not recommended to give a zero length extension when in place editing files, as it risks corruption or partial content in situations where disk space is exhausted, etc.
ed
There is definitely a use for sed
and for in-place editing features of sed
, but when the UNIX standard is extended, we should always ask why the old UNIX standard did not include that feature. Though UNIX is not perfect, the orthogonality and completeness of the tools has been developed to be quite near to perfection, at least for purposes that where visible around 1970: Text editing and automated text editing was surely visible around that time.
Actually, the idea of sed
is not to edit a file in place, but to edit a stream. That's why the name sed
is a short form of stream editor. Take away the s
, and you get the tool that was actually designed for file editing: ed
:
printf 'g/what to replace/s//with what to replace/g\nw\nq\n' | ed file
or cat file_edit_commands | ed file
.