in reply to Remove Duplicates!! Please Help
A one-liner:
perl -lnae 'print unless $seen{$F[0]}++' < file2.txt > file1.txt
Update: The OP needed the last entry if there are duplicates, the above solution took the first entry. Here's an alternative solutionthat requires module Tie::Hash::Indexed to be installed:
$ perl -MTie::Hash::Indexed -lane '\ sub BEGIN {tie %seen, "Tie::Hash::Indexed"};\ sub END {print $seen{$_} for keys %seen};\ $seen{$F[0]} = $_' file2.txt > file1.txt
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Remove Duplicates!! Please Help
by NetWallah (Canon) on Jan 03, 2008 at 16:16 UTC | |
Re^2: Remove Duplicates!! Please Help
by alexm (Chaplain) on Jan 03, 2008 at 20:12 UTC |
In Section
Seekers of Perl Wisdom