Use this Perl one-liner to delete all duplicates, whether adjacent or not:
perl -ne 'print unless $seen{$_}++;' input.txt > output.txt
To delete only adjacent duplicates (as in UNIX uniq command):
perl -ne 'print unless $_ eq $prev; $prev = $_; ' input.txt > output.txt
The Perl one-liners use these command line flags:
-e : Tells Perl to look for code in-line, instead of in a file.
-n : Loop over the input one line at a time, assigning it to $_ by default.
When the line is seen for the first time, $seen{$_} is evaluated first, and is false, so the line is printed. Then, $seen{$_} is incremented by one, which makes it true every time the line is seen again (thus the same line is not printed any more).
The first one-liner avoids reading the entire file into memory all at once, which could be important for inputs with lots of long duplicated lines. Only the first occurrence of every line is stored in memory, together with its number of occurrences.
SEE ALSO:
joinstatement will do, but it is in fact not doing anything. The loop is redundant, you can just grep the whole file and print it right away. E.g.perl -e'print grep !$seen{$_}++, <>;' input > outputjoinis used to concatenate string pieces into one string