I want to delete the consecutive duplicate lines. i.e. for example
**test.txt**
car
speed is good
bike
slower than car
plane
super fast
super fast
bullet train
super fast
This removes all the duplicate lines except the 1st occurance.
perl -ne 'print unless $a{$_}++'
But i want the ouput to be
**test.txt**
car
speed is good
bike
slower than car
plane
super fast
bullet train
super fast
I tried this oneliner but this doesnt do anything but just prints the input.
perl -00 -F'<\w+>|</\w+>' -i.bak -lane 'foreach(@F){if ($_=~/\w+/ && ($a ne $_)){print "$_";$a=$_;}}'
How to do this???
I also wanted to keep track of how many duplicates were suppressed and only skip consecutive duplicates.
While this is not exactly what the OP asked, it is a variant which others may find useful:
It produced something like this with my data (a database restore log):
Try:
Why don't you just use
uniq
?Results:
You can also do this with
awk
: