简体   繁体   中英

How do I remove duplicates AND the originals from a list in Sublime Text 3?

Edit > Permute Lines > Unique is great for removing duplicate from a list in Sublime Text. But what if I wanted to remove all matching results instead? For example:

james
james
bobby
mary
ann
ann

The above list of names would become:

bobby
mary

Because bobby and mary are the only names that only appear once.

If you don't mind your lines being sorted, you could do it like this:

  1. Edit > Sort Lines
  2. Find > Replace...
  3. Ensure RegEx mode is on
  4. Find What: (^.*$\\n)\\1+
  5. Replace With: (blank)

Although, sorting wouldn't be necessary if all the duplicates are next to each other, as per your example. eg it would even work with the following:

james
james
bobby
mary
ann
ann
james
james
james

Note that this regex requires the last line to have a trailing newline character, if it is a duplicate, otherwise it won't find it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM