Skip to content

Remove Duplicate Lines

Keep the first copy of each line. a, then a, then b becomes a and b. Blank lines are dropped. The page does not sort the lines.

Result

Enter lines

How to Use

  1. 1 Enter up to 20000 characters.
  2. 2 Choose Remove duplicate lines.
  3. 3 a, a, b becomes two lines.

Example Output

  • a a b becomes a and b.

About This Tool

Comparison uses the line after trimming spaces. The first copy stays where it was.

Using Remove Duplicate Lines

Remove Duplicate Lines keeps the first copy of each line. The lines field starts as a, then a, then b, on three lines. Choose Remove duplicate lines. The label above the headline reads Lines kept. The headline is 2 lines. The lines-kept line is 2. The result text is a, then b, in that order. Blank lines are dropped. The page does not sort the lines. Comparison uses the line after trimming spaces at the ends.

The first a stays. The second a is a later copy of the same trimmed line, so it is dropped. b has not been seen, so b stays under a. The steps under the result say to trim each line, drop blank lines and later copies, and keep the first copy in its original order. Run the same three lines again and the headline stays 2 lines. The result text stays a, then b. The page does not rearrange those two lines into alphabetical order.

A blank line between a and b is dropped, and it does not become a kept line. The headline is still 2 lines when the other lines are a and b. A line that is only spaces is blank after trimming, so it is dropped too. The ends of a line are trimmed before the comparison, so a line that is a with spaces on the ends matches a plain a. The first of those copies stays, and the kept text is the trimmed line. Spaces inside a line stay. The page does not fold a double space in the middle into one space.

The field allows from 1 to 20000 characters. An empty field says Enter from 1 to 20000 characters. A paste longer than 20000 characters uses that same message. The page does not store the text. Copy result copies the kept lines. For the starting field it copies a, then b. It does not copy the headline 2 lines in place of those lines. Reset returns the field to a, a, and b, and the headline to Enter lines.

A line with a space in the middle is not the same as that line with the space removed. a b and ab both stay if you paste both, and the headline counts them separately. The page does not fold the inner space. It also does not change a to A. Paste a, then A, then b, and the headline is 3 lines, with a, A, and b kept in that order. The second a in the starting sample is the one that disappears, because it matches the first a after trimming. That is the whole of the match. Spelling that differs by a single character stays.

b, then a, then b becomes b, then a. The headline is still 2 lines, because two distinct trimmed lines remain. The first b stays, a stays, and the later b is dropped. The order is the order of the first copies, which is b then a. That order is not a sort. The same rule covers the starting sample: the first a stays, and b follows it.

What the Kept Lines Are

The kept lines are the first copy of each trimmed line, in the order those first copies appeared. For a, then a, then b, the headline is 2 lines. The label above it reads Lines kept. The lines-kept line is 2. The result text is a, then b. The second a is gone. b remains because it is not a copy of a. Blank lines are dropped before that comparison, so they never become a kept line of their own.

The page does not sort. b, then a, then a second b, stays b then a. The headline is 2 lines for that paste as well. A sort would put a before b. This page leaves the first copies where they were. Read the result text, not only the headline. The headline counts the lines. The text shows which lines remain and in which order.

How a, a, and b Become Two Lines

The page splits the field on line breaks. It trims each line. It drops a line that is empty after that trim. It drops a line whose trimmed text has already been kept. It keeps the first copy. a is kept. The next a matches that copy, so it is dropped. b is new, so it is kept. The headline is 2 lines. The result text is a, then b. The steps under the result follow the trim, the drops, and the original order. The page does not sort those kept lines.

Alphabetical order is a different pass. The Alphabetical Sorter sorts one item per line from A to Z. banana, apple, and cherry become apple, banana, and cherry. That page does not change the spelling. Use it when you want A-to-Z order. Use this page when you want the first copy of each line and the original order of those first copies. a then b is the duplicate-line sample. apple, banana, and cherry is the sorter sample.

What Trimming Changes, and What It Leaves

Trimming removes spaces at the ends of a line before the comparison. A line that is a space, then a, then a space, matches a line that is only a. The first copy stays, and the kept text is a without those end spaces. A later copy of that trimmed a is dropped. Spaces that sit in the middle of the line are not removed. A line with two spaces between words does not become a line with one space. It is compared as that longer line.

Blank lines are dropped, including a line that becomes empty only after trimming. They do not count in the headline. The starting sample has no blank line, and the headline is 2 lines because a and b remain. Add a blank line and the headline stays 2 lines for a and b. The page does not store the text after the run. The kept lines are on the page until you change the field or reset.

The Starting Lines, Then b Before a

Leave the field as a, then a, then b. Choose Remove duplicate lines. The headline is 2 lines. The lines-kept line is 2. The result text is a, then b. Run it again. The figures match. Change the field to b, then a, then b. The headline is 2 lines, and the result text is b, then a. The later b is the dropped copy. Change the field back to a, a, and b. The result text returns to a, then b, and the headline is 2 lines again.

Folding every gap into one space is a different cleanup. The Text Cleaner trims the ends and folds repeated spaces, tabs, and line breaks into one space. Hello followed by three spaces and world becomes Hello world. The headline there is the character count 11. That page does not store the text. Use it when you want one space between words, including across line breaks. Use this page when you want separate lines kept, with later copies removed. Hello world is one cleaned line. a then b is two kept lines.

The Character Bound and an Empty Field

The field must contain from 1 to 20000 characters. Empty text says Enter from 1 to 20000 characters. Text longer than 20000 characters says the same. A field that trims to nothing uses that message too, so a box of only spaces does not become a kept line. The lines-kept line stays clear when that message is the headline. The page does not store the text, and it does not keep a previous result after a failed run.

A line is compared after trimming, and the match is the trimmed text itself. a and A are different lines, so both stay if you paste both. The headline for a, then A, then b is 3 lines, and the result text keeps a, A, and b in that order. The page does not change case to make them match. It also does not sort them. The 20000 character bound is on the paste, not on the number of kept lines.

Lines People Expect the Page to Reorder

A common miss is to expect a, a, b to come back as a single line. The second a is dropped, and b stays. The headline is 2 lines, and the text is a then b. Another miss is to expect b, a, b to come back as a then b. The first copies stay in place, so the text is b then a. The page does not sort. Another miss is to expect a blank line to remain. Blank lines are dropped. Another miss is to expect spaces in the middle of a line to collapse. Only the ends are trimmed. Another miss is to expect the page to store the text. It does not.

Reversing characters is a different rewrite. The Reverse Text Generator reverses the characters in the text you type. Hello becomes olleH. That page does not reverse the meaning of the words. Use it when you want the characters backward. Use this page when you want later copies of a line removed and the first copies left in order. olleH is a reversed word. a then b is the kept sample, and the letters inside a and b are not reversed.

Two Copies, a Blank Line, and a Different Case

Enter a, then a, then b. Remove duplicate lines. The headline is 2 lines, and the result text is a then b. Enter b, then a, then b. The headline is 2 lines, and the result text is b then a. Put a blank line between a and b, with only one a. The blank line is dropped. The headline is 2 lines, and the text is a then b. Restore a, a, and b, and confirm 2 lines again.

Enter a, then A. The headline is 2 lines, because the comparison does not fold case. The result text keeps both lines. Enter a line that is only spaces. After you also clear the other lines, an empty trim says Enter from 1 to 20000 characters. Restore a, a, and b. Confirm the headline is 2 lines and the result text is a then b before you leave the sample.

Keeping the Lines That Stayed

Copy the kept lines. For the starting field the copy is a, then b. Write the headline 2 lines beside that copy if you also want the count. A note that says only 2 lines can be a then b, or b then a, or a longer list that also has two first copies. The result text shows the order. The page does not sort, and it does not store the text. Keep the copy that matches the field you used. Reset returns the field to a, a, and b, and the headline to Enter lines, so copy the kept lines first.

Changing case is a different record of the same letters. The Uppercase Converter turns the text you type into upper case. hello becomes HELLO. That page does not change any other case. Use it when you want upper case. Use this page when you want duplicate lines removed. HELLO is a case change. a then b is the kept sample. This page would keep hello and HELLO as two lines, because those trimmed lines are not the same.

First Copies, in the Order You Typed

The headline answers how many lines remain after blank lines and later copies are dropped. a, then a, then b becomes a then b, and the headline is 2 lines. The first copy stays. The page does not sort. b before a stays b then a when the extra b is the duplicate. Spaces at the ends are trimmed before the comparison. Spaces in the middle of a line stay. The page does not store the text.

Checking the First Copy Against the Headline

Walk the lines from top to bottom. Trim the ends. Skip a blank line. Skip a trimmed line you have already kept. Write down the first copy when it is new. Count those lines and compare with the headline. For a, a, and b, the check is a then b, and the headline is 2 lines. For b, a, and b, the check is b then a, and the headline is 2 lines. For a and A, the check is both lines, and the headline is 2 lines. An error headline means the lines were not kept. The message Enter from 1 to 20000 characters means the field was empty or too long. The label above a successful headline reads Lines kept.

Lower case is a different change. The Lowercase Converter turns the text you type into lower case. Hello becomes hello. Digits and spaces stay as typed. Use it when you want lower case. Use this page when you want the first copy of each line. hello is a case change. a then b is the kept sample. Lower case would make A match a only after you run that other page. This page does not do that.

Frequently Asked Questions

What do the lines a, a, and b return?

The headline is 2 lines. The result text is a, then b. The second a is dropped. The first a stays, and b stays under it. The page does not sort those lines. The same three lines always rebuild that result.

Does the page sort?

No. The page does not sort. b, then a, then b becomes b then a. The headline is 2 lines. The first copy of each trimmed line stays in its original place. A later copy is dropped.

What happens to blank lines?

Blank lines are dropped. A line that is only spaces is blank after trimming, so it is dropped too. A blank line between a and b does not change the headline. The result is still a then b, and the headline is 2 lines.

Which copy stays?

The first copy stays. Later copies of the same trimmed line are dropped. a, then a, keeps one a. The kept text uses the trimmed line, so spaces at the ends do not remain on that copy.

Do a and A count as duplicates?

No. The comparison uses the trimmed line as typed. a and A both stay. The page does not change case. The headline for a, A, and b is 3 lines, with those three lines in that order.

Are spaces inside a line removed?

No. Only the ends are trimmed. Spaces in the middle of a line stay. Two lines match when their trimmed text is the same. A double space in the middle keeps that line distinct from a single space.

How much text can the field hold?

From 1 to 20000 characters. An empty field or a paste past that bound says Enter from 1 to 20000 characters. The page does not store the text. A failed run clears the kept lines.

What does Copy result copy?

It copies the kept lines. For the starting field that copy is a, then b. It does not replace those lines with the headline 2 lines. Reset restores a, a, and b and the headline to Enter lines, so copy the kept lines first if you want to keep them.