#!/usr/bin/perl -w

my (%hosts, %servs);
while (<DATA>) {
  chomp;
  my ($host, $server) = (split /,\s*/)[0,4];
  $hosts{$host}++ if ($host);
  $servs{$server}++ if ($server);
}

my @dup_hosts = map { substr $_,0,5,''; $_ }
          grep { $hosts{$_} > 1 }  keys %hosts;

my @dup_servs = map { substr $_,0,5,''; $_ }
          grep { $servs{$_} > 1 }  keys %servs;

local $, = $/;
print "duplicate hosts:\n";
print @dup_hosts;
print "\n\nduplicate servers:\n";
print @dup_servs;






__DATA__

Host=Nirus,TCPIP,inxcp011,connected,Serv=rxmcpp1

Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp2

Host=Rome,TCPIP,inxcp011,connected, Serv=rxmcpp1

Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp1

Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp3

Host=Spring,TCPIP,inxcp011,connected, Serv=rxmcpp

Host=Spring,TCPIP,inxcp011,connected, Serv=rxmcpp1

Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp1

Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp1

Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp1

Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp1

__END__

On Wed, Apr 16, 2008 at 2:16 PM, Wagner, David --- Senior Programmer Analyst
--- WGO <[EMAIL PROTECTED]> wrote:

>
> > -----Original Message-----
> > From: Manoj [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, April 16, 2008 12:00
> > To: 'Perl Beginners'
> > Subject: CSV duplicate
> >
> > Hello List,
> >
> >
> >
> > Scenario:
> >
> > CSV file
> >
> > Host=Nirus,TCPIP,inxcp011,connected,Serv=rxmcpp1
> >
> > Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp2
> >
> > Host=Rome,TCPIP,inxcp011,connected, Serv=rxmcpp1
> >
> > Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp1
> >
> > Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp3
> >
> > Host=Spring,TCPIP,inxcp011,connected, Serv=rxmcpp
> >
> > Host=Spring,TCPIP,inxcp011,connected, Serv=rxmcpp1
> >
> > Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp1
> >
> > Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp1
> >
> > Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp1
> >
> > Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp1
> >
> >
> >
> > Required output is
> >
> > Nirus
> >
> > Spring
> >
> >
>         So what are you searching on or looking at to determine that you
> want only those two? The last depends on the number of rcds and are you
> only concerned with the server name?
>
> Wags ;)
>
> >
> > There is one more requirement I need to sort the 5th column
> > and sort them
> > and fetch which ever is duplicate. So in this one I need to print
> >
> > rxmcpp1 to screen.
> >
> >
>
> **********************************************************************
> This message contains information that is confidential and proprietary to
> FedEx Freight or its affiliates.  It is intended only for the recipient
> named and for the express  purpose(s) described therein.  Any other use is
> prohibited.
> **********************************************************************
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>

Reply via email to