0

I was looking for a way to delete non-juxtaposed duplicate lines in ed such as,

ed is a terminal editor
sam is a bitmap editor
emacs is a macro editor
ed is a terminal editor

I am hoping to produce:

ed is a terminal editor
sam is a bitmap editor
emacs is a macro editor
Edman
  • 492

1 Answers1

3

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).

Kusalananda
  • 333,661