You could possibly use
e !ed -s % <script
if the script ends with outputting the modified editing buffer, i.e. if the script ends with ,p
and Q
. This would replace the contents of the current editing buffer with the output of the command after !
. The %
in the command will automatically be replaced by the current file's name (this command will not change the name of the current file).
Just remember to w
first so that the spawned ed
sees your edits up until that point.
(This does not seem to apply to your example script, but...) If the script does in-place editing of the file so that the file is saved back to disk at the end, then use
!ed -s % <script
e
This executes your ed
command in a shell and then replaces the current editing buffer with the updated file contents. Again, do not forget to w
first.
Further explanation:
The e !somecommand
command discards the current editing buffer and replaces it with the output of somecommand
.
This means that e !ed -s % <script
would be appropriate if the script
editing script outputs the final result on standard output, and you would like to edit that output.
The e
command, with no further argument, re-opens the current file and replaces the editing buffer with that file's content. If this is preceded by !somecommand
where somecommand
changes the current file, then this is how you incorporate those changes into the editing session.
This means that !ed -s % <script
followed by e
would be what you may want to use if the script
editing script saves the modified document back to the same name (rather than writing it to standard output).
e !ed -s % <script
. – Kusalananda Jul 14 '21 at 14:58cat cript | ed - file
– nezabudka Jul 14 '21 at 15:29