How to delete duplicate lines in a file without sorting it in Unix?

后端 未结 9 1647
Happy的楠姐
Happy的楠姐 2020-11-22 17:26

Is there a way to delete duplicate lines in a file in Unix?

I can do it with sort -u and uniq commands, but I want to use sed

9条回答
  •  日久生厌
    2020-11-22 17:55

    An alternative way using Vim(Vi compatible):

    Delete duplicate, consecutive lines from a file:

    vim -esu NONE +'g/\v^(.*)\n\1$/d' +wq

    Delete duplicate, nonconsecutive and nonempty lines from a file:

    vim -esu NONE +'g/\v^(.+)$\_.{-}^\1$/d' +wq

提交回复
热议问题