Next: , Up: Scripts

2.5.1 ed Scripts

diff can produce commands that direct the ed text editor to change the first file into the second file. Long ago, this was the only output mode that was suitable for editing one file into another automatically; today, with patch, it is almost obsolete. Use the --ed (-e) option to select this output format.

Like the normal format (see Normal), this output format does not show any context; unlike the normal format, it does not include the information necessary to apply the diff in reverse (to produce the first file if all you have is the second file and the diff).

If the file d contains the output of ‘diff -e old new’, then the command ‘(cat d && echo w) | ed - old’ edits old to make it a copy of new. More generally, if d1, d2, ..., dN contain the outputs of ‘diff -e old new1’, ‘diff -e new1 new2’, ..., ‘diff -e newN-1 newN’, respectively, then the command ‘(cat d1 d2 ... dN && echo w) | ed - old’ edits old to make it a copy of newN.