This is another case where it's easier to call an external tool to do the work and then edit the output of that tool:
$ ed file
95
,n
1 ed is a terminal editor
2 sam is a bitmap editor
3 emacs is a macro editor
4 ed is a terminal editor
e !awk '!seen[$0]++' %
awk '!seen[$0]++' file
71
,n
1 ed is a terminal editor
2 sam is a bitmap editor
3 emacs is a macro editor
The awk
command called via e !
here outputs lines that have not been seen before, and will ignore lines that have been seen. You will find examples of this specific use of awk
in a number of answers on this site (e.g. here, and with explanation here).