A copied text export may repeat a line immediately while using the same line again later on purpose. Removing every duplicate would delete that later occurrence too. Collapse only the adjacent runs you have identified as unwanted, and preserve the rest of the sequence.
This procedure edits nonempty plain-text rows. It compares exact capitalization and spaces, keeps genuinely empty separators, and does not decide which repetitions are meaningful.
Separate adjacent cleanup from a unique-line list
Save the original and start with this controlled example, without a final newline:
Ready
Ready
Inspect tray
Ready
The first two rows are the unwanted adjacent repeat. The final Ready belongs to a later point in the sequence and must remain.
As a comparison, paste the sample into the Duplicate Line Remover, uncheck all five options and select Remove Duplicates. The current result is:
Ready
Inspect tray
That tool keeps one representative of each exact line across the complete input. Its four input rows become two output rows. Sorting is not the cause: the nonadjacent final occurrence is removed by global deduplication. The unique-line list guide covers that different goal.
Replace only consecutive exact rows
Return to the saved original. Open Find and Replace Text and paste the four-line sample into Your text.
- Enable Use regular expression, Match case and Replace all.
- Leave Whole word only off.
- Enter the following in Find, with single backslashes and no surrounding slashes or flags:
(^|\r?\n)([^\r\n]+)(?:\r?\n\2)+(?=\r?\n|$)
Set Replace with to $1$2, with no space between the tokens, and select Replace. Expect one replacement and this separate output:
Ready
Inspect tray
Ready
The main sample changes from 30 characters to 24. The adjacent extra row is gone, and the later occurrence remains in its original position. The input box remains unchanged, so read the result rather than assuming the source was overwritten.
Check the whole-line boundaries and the count
Group 1 captures the start or preceding line break. Group 2 captures a nonempty row. The \2 backreference requires the following row to contain the same text; MDN explains this captured-text behavior in its backreference guide. Keeping Match case enabled preserves the exact comparison.
The final lookahead requires a line break or the end of the input after the repeated text. It prevents A from being accepted merely as the beginning of AB. MDN’s lookahead reference describes checking the following text without consuming it. The replacement restores the captured boundary and one copy of the row.
The reported count measures matched runs, not removed rows. In a separate test, three adjacent Ready rows followed by two Inspect tray rows and a final Ready produced two replacements while removing three excess rows.
Review separators and meaningful differences
Our exact-source tests and an independent row-by-row check also confirmed these limits:
| Situation | Result under this rule |
|---|---|
| Two identical neighboring nonempty rows | One copy remains |
| A genuinely empty row between equal rows | The separation stops that duplicate run |
Ready beside ready |
Both remain |
| Equal visible words with different trailing spaces | Both remain |
| Two rows each containing one ordinary space | They collapse as matching nonempty text |
Empty means zero characters here. Space-only and tab-only rows are not empty to this pattern. Inspect those separators before accepting an edit. The line-break alternatives handle LF and CRLF strings; bare carriage-return endings need a different procedure. This is not a method for preserving a file’s exact original bytes.
Keep structured records outside this workflow. The CSV line-removal example shows why a physical row can be part of a larger record. Before copying a reviewed result, compare the first and last rows, later recurrences and meaningful spacing, then check the text in its destination.