This question already addresses how to remove duplicate lines, but enforces that the list is sorted first.
I would like to perform the remove contiguous duplicate lines step (i.e. uniq
) without first sorting them.
Example before:
Foo
Foo
Bar
Bar
Example after:
Foo
Bar
Indeed, both commands can remove duplicate lines from input, for example, a text file. However, the uniq command requires the file to be sorted, and sort first sorts lines in the file. In this tutorial, we'll explore a method to remove duplicate lines from an input file without sorting.
The uniq command is used to remove duplicate lines from a text file in Linux. By default, this command discards all but the first of adjacent repeated lines, so that no output lines are repeated. Optionally, it can instead only print duplicate lines.
:%!uniq
if you're on a unix system, or a system that has the uniq
program
Just found the solution here. The following regex works correctly:
g/^\(.*\)$\n\1$/d
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With