Removing duplicate rows in vi?

后端 未结 14 2183
无人及你
无人及你 2021-01-29 23:10

I have a text file that contains a long list of entries (one on each line). Some of these are duplicates, and I would like to know if it is possible (and if so, how) to remove

14条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-29 23:44

    Try this:

    :%s/^\(.*\)\(\n\1\)\+$/\1/
    

    It searches for any line immediately followed by one or more copies of itself, and replaces it with a single copy.

    Make a copy of your file though before you try it. It's untested.

提交回复
热议问题