Hi,
I need to print lines if it appears more than 3 times in a file looking only at the second column.
I have written the below code. But it will look for the complete words in a line.
#!/usr/bin/perl
use strict;
use warnings;
my $file = 'file.txt';
my %seen = ();
{
local @ARGV = ($file);
while(<>){
$seen{$_}++;
next if $seen{$_} > 1;
print;
}
}
foreach my $keys ( sort {$seen{$b} <=> $seen{$a}} keys %seen) {
if ($seen{$keys} >=3){
print "$keys = $seen{$keys}\n";
}
}
My file loks like below. I am looking for the field with "PATTERN"
1362227457 TEST PATTERN none USER LOGIN1 1 INVALID USER
1362227691 TEST PATTERN2 none USER1 LOGIN2 1 INVALID USER
1362227784 TEST PATTERN none USER10 LOGIN3 1 INVALID USER
1362228006 TEST PATTERN none USER LOGIN1 1 LOGIN FAILED
1362228101 TEST PATTERN none USER LOGIN1 1 LOGIN FAILED
1362228328 TEST PATTERN none USER LOGIN1 1 LOGIN FAILED
1362229375 TEST PATTERN none USER LOGIN1 1 LOGIN FAILED
1362230359 TEST PATTERN none USER LOGIN2 1 LOGIN FAILED
1362230359 TEST PATTERN none USER LOGIN2 1 LOGIN FAILED
1362230359 TEST PATTERN4 none USER LOGIN2 1 LOGIN FAILED
1362230359 a
1362230359 a
1362230359 a