Manoj wrote:
Hello List,
Hello,
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
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 should be close to what you want:
my %data;
while ( <FILE> ) {
chomp;
for ( map [ split /=/ ], ( split /\s*,\s*/ )[ 0, -1 ] ) {
$data{ $_->[ 0 ] }{ $_->[ 1 ] }++;
}
}
for my $type ( keys %data ) {
print "Duplicate $type\n";
for my $key ( keys %{ $data{ $type } } ) {
print "$key\n" if $data{ $type }{ $key } > 1;
}
print "\n";
}
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/