perl -ne '$h{$_}= $.; END{print for sort {$h{$a} <=> $h{$b}} keys %h}' test.txt