All posts

Tools

Remove Duplicate Lines Without Changing Their Order

Clean up a pasted list with tested input and output examples. See how trimming spaces, skipping empty lines, and ignoring case change which entries remain.

Published and maintained by Sambro · Report a correction

6 min read Duplicate linesList cleanupText tools

Keep the first occurrence of each entry

When you combine tags or copy a list from several messages, repeated entries can be scattered far apart. Sorting the list makes duplicates easier to spot, but also changes a useful order, such as the order in which topics were raised. You can remove later copies while leaving the first occurrences in place.

Sambro's Duplicate Line Remover at Duplicate line remover compares one line at a time and keeps the first matching entry. Start with one item per line. Commas, tabs, and semicolons inside a line do not split it into separate items.

For a copied roster, decide what identifies a person before removing anything. Two identical names can belong to different people. This tool finds repeated text; it cannot decide whether two records describe the same person.

Try this eight-line example

Copy the input below into the tool. The first line has two spaces before and after Design, and the fourth line is empty. Keep the defaults: Trim line edges on, Remove empty lines on, and Ignore case off. Choose Remove duplicates.

The result has four lines: Design, Research, TODO, and todo. The counts are 8 input lines, 4 result lines, 3 duplicates removed, and 1 empty line skipped. Research stays ahead of TODO because its first occurrence was earlier. TODO and todo remain separate while case matching is exact.

Input: 8 lines, including one empty line
  Design  
Research
Design

TODO
todo
Research
TODO
Result with the default options: 4 lines
Design
Research
TODO
todo

Trimming changes both the comparison and the output

With trimming on, the spaces around the first Design are removed before comparison and from the output. That makes the later Design a duplicate. Spaces inside an entry are left alone: Team Alpha and Team Alpha, with one and two internal spaces, remain two different lines.

Turn trimming off while leaving the other defaults unchanged, then choose Remove duplicates again. The same input produces five lines, with two duplicates removed and one empty line skipped. The padded first line and the unpadded Design are different entries. The first line in the output below still has its original surrounding spaces.

Leave trimming off when indentation or a trailing space is meaningful. Even then, the tool changes the list by removing repeated lines, so keep the original before using it on source code or structured text.

Result with trimming off: 5 lines; the first line keeps its spaces
  Design  
Research
Design
TODO
todo

Ignoring case keeps the first spelling

Turn trimming back on, enable Ignore case, and run the tool again. TODO and todo now match. The output has three lines, with four duplicates removed and one empty line skipped. The first spelling, TODO, is retained; the output is not converted to lowercase.

This option suits tags whose capitalization is only a presentation choice. Leave it off for case-sensitive identifiers or any list where a capital letter might change the meaning. Matching uses JavaScript lowercase conversion. It does not perform language-aware matching, remove accents, or normalize different Unicode representations of the same-looking text.

Result with trimming and case-insensitive matching on: 3 lines
Design
Research
TODO

Why empty lines and line counts may look different

Remove empty lines removes both empty lines and lines containing only whitespace, even when trimming is off. Skipped empty lines have their own count; they are not included in the duplicates-removed count. In the first example, 4 kept + 3 duplicates + 1 empty line accounts for all 8 input lines.

If you turn Remove empty lines off while leaving trimming on, the first empty line remains and later empty lines count as duplicates. This will not preserve paragraph spacing. Use it for a list where a single empty entry is intentional, rather than for tidying a document's layout.

Windows CRLF, LF, and older CR line endings are recognized. A single final line break ends the last line without adding another empty entry; two consecutive line breaks can create an empty line. Output uses LF line endings. For example, A, A, an empty line, and B followed by a final line break count as four input lines and produce A then B with the default options.

When to keep the work in Excel

A pasted single-column list is a good fit for this tool. A table with names, order numbers, and amounts needs a rule about which columns identify a duplicate. The line remover compares the whole line and does not understand spreadsheet columns or quoted CSV fields. A CSV cell that contains a line break also breaks the one-item-per-line assumption.

Excel's Remove Duplicates lets you choose the comparison columns. Microsoft documents that it keeps the first occurrence and removes a matching row across the selected table or range, including its other columns. Make a copy before changing the original table. See Microsoft's instructions: Microsoft Excel — filter or remove duplicates .

Do not deduplicate just the name column and paste it back beside untouched phone numbers or amounts. The rows can stop lining up. Keep related fields together and choose a reliable key.

Check the result before copying it elsewhere

The duplicate comparison and result generation run in the browser; the tool does not upload the pasted list for processing. That does not remove risks from browser extensions, a shared screen, or clipboard history. Use invented sample data to test your settings, and follow your organization's rules before handling confidential lists.

Keep an original copy, check a few entries whose spacing or capitalization differs, then copy the result into its destination and check the line boundaries there. Changing an option clears the old result. Run the tool again and inspect the new result rather than relying on an earlier count.

The examples in this guide were checked against the tool's processing function on October 16, 2026. They demonstrate the listed behaviors, not a speed benchmark or a guarantee that matching text represents matching people. Try your own non-sensitive list at Duplicate line remover .

Back to Sambro Blog