Hello,
i found this code on a web page which is said to be valid for only gnu linux and delete all lines except duplicate ones, i hope it works (sorry im using solaris10, couldnt try)
# delete all lines except duplicate lines (emulates "uniq -d").
Yes,
first of all, the code is wrong
It should be:
unless $_{$F[0],$F[1]}++
... not:
unless $_{@F[0..1]}++
So the script becomes:
perl -ane'print unless $_{$F[0],$F[1]}++' infile
First the command line switches:
So we have the input file read line by line and the @F array automatically populated.
print unless $_{$F[0],$F[1]}++
Print the current record unless the expression ${$F[0],$F[1]}++ returns true in boolean context. We build the hash % whose keys (the concatenation of the first two fields with the subscript separator) are associated with auto-incremented integers. When we see a given key ($F[0] $; $F[1] - the first and the second fields) for the first time, because of the post-incrementing (k++ and not ++k ) its value is 0, i.e. false, so it prints the record.