Hi. Thanks for the quick responses.
Adding the echo 'Q' seems to resolve. I assume there is no issue using same on prior releases of ed? "You are taking the deltas from the standard output of ed, which is for human consumption, not to be used as output to be written to a file." The deltas in question are generated with diff -e to produce the ed output. Jeff -----Original Message----- From: Antonio Diaz Diaz <anto...@gnu.org> Sent: Tuesday, October 3, 2023 11:18 AM To: Danie Theron - DSV <danie.the...@dsv.com> Cc: bug-ed@gnu.org; Development Team <d...@roundtable-software.com> Subject: Re: Bug introduced in ed v1.14 (up to v1.19) corrupting full file which delta changes are applied to Hello Danie, Danie Theron - DSV wrote: > This is working fine up to v1.13 of "ed", but since v1.14 up to the > latest version v1.19, the deltas are not being applied correctly > causing corruption in the reconstruction of programs. You are taking the deltas from the standard output of ed, which is for human consumption, not to be used as output to be written to a file. This may have worked with older versions of ed, but it no longer is expected to work. For example, POSIX[1] states that: If changes have been made in the buffer since the last w command that wrote the entire buffer, ed shall warn the user if an attempt is made to destroy the editor buffer via the e or q commands. The ed utility shall write the string: "?\n" (followed by an explanatory message if help mode has been enabled via the H command) to standard output and shall continue in command mode with the current line number unchanged. and If an end-of-file is detected on standard input: [...] If the ed utility is in command mode, it shall act as if a q command had been entered. [1] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html The cause of the '?' being inserted into the reconstructed files is that ed is reaching the end of file on standard input with the buffer modified: $ (cat textfile_v1.1_delta.txt ; echo '1,$p') | ed -vs textfile_v1.0.txt | diff textfile_v1.1.txt - 7a8,9 > ? > Warning: buffer modified A workaround may be to exit ed unconditionally with command 'Q': $ (cat textfile_v1.1_delta.txt ; echo '1,$p' ; echo 'Q') | ed -s textfile_v1.0.txt | diff textfile_v1.1.txt - But probably a better solution would be to use the 'w' command of 'ed', or to use 'patch' instead of 'ed' to apply the patches. Best regards, Antonio.