- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Help: perl count/sort
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2006 02:05 AM
тАО09-01-2006 02:05 AM
05-JUL-06
05-JUL-06
05-JUL-06
05-JUL-06
05-JUL-06
08-JUL-06
08-JUL-06
08-JUL-06
10-JUL-06
15-JUL-06
15-JUL-06
15-JUL-06
15-JUL-06
25-JUL-06
25-JUL-06
01-AUG-06
01-AUG-06
02-AUG-06
02-AUG-06
05-AUG-06
05-AUG-06
07-AUG-06
07-AUG-06
07-AUG-06
07-AUG-06
09-AUG-06
09-AUG-06
09-AUG-06
09-AUG-06
11-AUG-06
11-AUG-06
14-AUG-06
14-AUG-06
14-AUG-06
14-AUG-06
14-AUG-06
14-AUG-06
14-AUG-06
14-AUG-06
18-AUG-06
18-AUG-06
18-AUG-06
I will like to produce the following output using perl.
05-JUL-06 : 5
08-JUL-06 : 3
10-JUL-06 : 1
15-JUL-06 : 4
25-JUL-06 : 2
01-AUG-06 : 2
02-AUG-06 : 2
05-AUG-06 : 2
07-AUG-06 : 4
09-AUG-06 : 4
11-AUG-06 : 2
14-AUG-06 : 8
18-AUG-06 : 3
Total : 42
I appreciate all help.
Thanks, in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2006 02:43 AM
тАО09-01-2006 02:43 AM
Re: Help: perl count/sort
use strict;
open FILE, "path to a file" or die "Couldn't open a file";
my $lines;
my %hash;
while (
chomp;
$lines++;
$hash{$_}++;
}
my @dates=sort keys %hash;
for (@dates)
{
print $_." : ".$hash{$_}."\n";
}
print "Total: $lines.\n";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2006 02:46 AM
тАО09-01-2006 02:46 AM
Re: Help: perl count/sort
open (INPUT, @ARGV[0]);
@lines=;
close (INPUT);
#now you have readed all form file in lines array
$prev_line=@lines[0];
$act_count=1;
$total_count=0;
foreach $line (@lines){
total_count++;
if ($line eq $prev_line){
$act_count++;
}
else {
print "$prev_line : $act_count\n";
$perv_line = $line;
$act_count=1;
}
}
print "Total : $total_count\n";
it's all and should be OK if there are no blank lines(if there are you should tak care about them).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2006 02:51 AM
тАО09-01-2006 02:51 AM
Re: Help: perl count/sort
for more help google is good (he always helped me). But if something is hard to understand and perl there are some hard construction, than ask us.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2006 03:30 AM
тАО09-01-2006 03:30 AM
Re: Help: perl count/sort
Thanks for your reply.
I'm new to perl. following are my script.
my $Process_File="test_file.txt";
open(FP,"$Process_File") or die "Could not open $Process_File: $!\n";
while (
@words = split ' ';
foreach $word (@words) {
$count{$word}{$ARGV}++;
$count++;
}
}
foreach $word (keys %count) {
$down_date = "$word";
$tot_count = join(", ",
map "$_: $count{$word}{$_}",
sort keys %{$count{$word}});
print "$down_date $tot_count\n"
}
close (FP);
print " \n";
print "Total : $count\n";
output:
11-AUG-06 : 2
15-AUG-06 : 4
07-AUG-06 : 4
01-AUG-06 : 2
25-JUL-06 : 2
10-JUL-06 : 1
08-JUL-06 : 3
14-AUG-06 : 8
05-AUG-06 : 2
02-AUG-06 : 2
18-AUG-06 : 3
09-AUG-06 : 4
05-JUL-06 : 5
Total : 42
Please advise what I'm doing wrong. I need output sorted by date all JUL the AUG. AUG then SEP etc......
Thanks.
JC.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2006 03:56 AM
тАО09-01-2006 03:56 AM
Re: Help: perl count/sort
Hope it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2006 07:41 AM
тАО09-01-2006 07:41 AM
SolutionThis assures that the order in which the data was placed in the array remains intact.
use strict;
open FILE, "path_to_file" or die "Couldn't open a file";
my (@entries,@uniq,%hash,$lines);
while (
chomp;
$lines++;
push @entries,$_; #place each in the array
}
for (@entries) {
push @uniq,$_ unless (defined($hash{$_})); #Need to avoid duplicated entries in output.
$hash{$_}++; #increment the count of duplicated lines.
}
print $_." : ".$hash{$_}."\n" for @uniq;
print "Total: $lines.\n";
Hope it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2006 09:33 AM
тАО09-01-2006 09:33 AM
Re: Help: perl count/sort
Perfect. Thanks, I appreciate all your reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2006 09:34 AM
тАО09-01-2006 09:34 AM