For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2007 > FW: remove line if field one is duplicate









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author FW: remove line if field one is duplicate
Greg John ** CTR ** Keenan

2007-02-28, 6:59 pm

<gjkeenan@alcatel-lucent.com> wrote:
> Hi,
>
> I have to combine several Unix password files and remove any duplicate
> accounts - putting this into LDAP.
>
> I have the following code that will remove any duplicate whole lines

but
> I need to remove lines only if the first field of the password file is

a
> duplicate.


This should work

perl -ne 'print unless $h{(split/:/)[0]}++'


Thanks Jeff & Chas

Both solutions work perfectly.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com