Remove Duplicate Lines
Remove duplicate lines or repeated words from text, with options to ignore case, trim whitespace, or sort lines.
Removes repeated lines from a list — emails, keywords, URLs, names — keeping the first occurrence of each line in its original order. The count under the result shows how many lines were removed.
Switched to words, it removes repeated words inside the text instead, such as a doubled “the the” in a draft, and leaves the lines, spacing and punctuation around them as they were.
Options
- Compare — Lines by default; Words compares the words inside the text (below).
- Keep — First of each by default keeps one copy of every line. Only unique drops every line that appears more than once, keeping just the lines that were never repeated.
- Ignore case — on by default: “Apple” and “apple” count as the same line.
- Only next to each other — off by default. On, a line counts as a repeat only right after its twin, as the Unix
uniqcommand does, so a line that comes back later in the list stays. - Ignore extra spaces — on by default: spaces and tabs at the start or end of a line don't make it different, and neither do runs of them inside it, so “a b” matches “a b”.
- Sort lines alphabetically — sorts the kept lines instead of keeping their original order, in the same standard order as Sort Text Lines, whatever your browser language.
- Remove empty lines — on by default: drops every blank line, including lines of only spaces.
The options affect only how lines are compared; the line that is kept appears exactly as you typed it. With empty lines kept, blank lines are never compared: each stays where it was, a removed line leaves the blank lines around it in place, and sorting puts them first.
With Words, a word is a run of letters, digits and apostrophes, with hyphens inside it (“e-mail”), as the Word Frequency Counter counts them; accented letters match however they were typed. Each repeat goes with the space before it, and the punctuation after it stays, so “the the, end” becomes “the, end”. Line breaks always stay, even when every word of a line goes. Keep, Ignore case and Only next to each other work as for lines; next to each other means nothing but spaces or a line break between, so “very, very” stays. The other options apply to lines only. Chinese and Japanese characters are never compared, since repeating one is ordinary writing.
Examples
An email list, with the default options
- Text
anna@example.com Ben@example.com anna@example.com ben@example.com
- Revealed
anna@example.com↵ Ben@example.com↵ anna@example.com·↵ ben@example.com
- Result
anna@example.com Ben@example.com
Shown with · for a space, → for a tab and ↵ for a line break.
2 duplicates removed: the second “anna” differs only by a trailing space, and “ben” only by case.
The same list, matching case
- Ignore case
- Off
- Result
anna@example.com Ben@example.com ben@example.com
With ignore case off, both spellings of Ben stay: 1 duplicate removed.
Doubled words in a draft
- Compare
- Words
- Only next to each other
- On
- Text
The the results are in. We checked the figures twice, then then once more.
- Result
The results are in. We checked the figures twice, then once more.
2 doubled words removed, case ignored by default. “The” comes back in “the figures”, but with only next to each other on, only the doubled one goes.
See also
- Sort Text Lines — for more sorting options, including reverse and random.