<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Help:  perl count/sort in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000909#M47726</link>
    <description>To complete what I mean - I've changed my previous code a bit. Now I collect the data into array and then I do all manipulations.&lt;BR /&gt;This assures that the order in which the data was placed in the array remains intact.&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;open FILE, "path_to_file" or die "Couldn't open a file";&lt;BR /&gt;my (@entries,@uniq,%hash,$lines);&lt;BR /&gt;while (&lt;FILE&gt;) {&lt;BR /&gt; chomp; &lt;BR /&gt; $lines++;&lt;BR /&gt; push @entries,$_; #place each in the array&lt;BR /&gt;}&lt;BR /&gt;for (@entries) {&lt;BR /&gt; push @uniq,$_ unless (defined($hash{$_})); #Need to avoid duplicated entries in output.&lt;BR /&gt; $hash{$_}++; #increment the count of duplicated lines.&lt;BR /&gt;}&lt;BR /&gt;print $_." : ".$hash{$_}."\n" for @uniq;&lt;BR /&gt;print "Total: $lines.\n";&lt;BR /&gt;&lt;BR /&gt;Hope it helps.&lt;/FILE&gt;</description>
    <pubDate>Fri, 01 Sep 2006 14:41:01 GMT</pubDate>
    <dc:creator>Alexander Chuzhoy</dc:creator>
    <dc:date>2006-09-01T14:41:01Z</dc:date>
    <item>
      <title>Help:  perl count/sort</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000903#M47720</link>
      <description>I have the following in a text file&lt;BR /&gt;&lt;BR /&gt;05-JUL-06&lt;BR /&gt;05-JUL-06&lt;BR /&gt;05-JUL-06&lt;BR /&gt;05-JUL-06&lt;BR /&gt;05-JUL-06&lt;BR /&gt;08-JUL-06&lt;BR /&gt;08-JUL-06&lt;BR /&gt;08-JUL-06&lt;BR /&gt;10-JUL-06&lt;BR /&gt;15-JUL-06&lt;BR /&gt;15-JUL-06&lt;BR /&gt;15-JUL-06&lt;BR /&gt;15-JUL-06&lt;BR /&gt;25-JUL-06&lt;BR /&gt;25-JUL-06&lt;BR /&gt;01-AUG-06&lt;BR /&gt;01-AUG-06&lt;BR /&gt;02-AUG-06&lt;BR /&gt;02-AUG-06&lt;BR /&gt;05-AUG-06&lt;BR /&gt;05-AUG-06&lt;BR /&gt;07-AUG-06&lt;BR /&gt;07-AUG-06&lt;BR /&gt;07-AUG-06&lt;BR /&gt;07-AUG-06&lt;BR /&gt;09-AUG-06&lt;BR /&gt;09-AUG-06&lt;BR /&gt;09-AUG-06&lt;BR /&gt;09-AUG-06&lt;BR /&gt;11-AUG-06&lt;BR /&gt;11-AUG-06&lt;BR /&gt;14-AUG-06&lt;BR /&gt;14-AUG-06&lt;BR /&gt;14-AUG-06&lt;BR /&gt;14-AUG-06&lt;BR /&gt;14-AUG-06&lt;BR /&gt;14-AUG-06&lt;BR /&gt;14-AUG-06&lt;BR /&gt;14-AUG-06&lt;BR /&gt;18-AUG-06&lt;BR /&gt;18-AUG-06&lt;BR /&gt;18-AUG-06&lt;BR /&gt;&lt;BR /&gt;I will like to produce the following output using perl.&lt;BR /&gt;&lt;BR /&gt;05-JUL-06  : 5&lt;BR /&gt;08-JUL-06  : 3&lt;BR /&gt;10-JUL-06  : 1&lt;BR /&gt;15-JUL-06  : 4&lt;BR /&gt;25-JUL-06  : 2&lt;BR /&gt;01-AUG-06  : 2&lt;BR /&gt;02-AUG-06  : 2&lt;BR /&gt;05-AUG-06  : 2&lt;BR /&gt;07-AUG-06  : 4&lt;BR /&gt;09-AUG-06  : 4&lt;BR /&gt;11-AUG-06  : 2&lt;BR /&gt;14-AUG-06  : 8&lt;BR /&gt;18-AUG-06  : 3&lt;BR /&gt;&lt;BR /&gt;Total      : 42&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I appreciate all help.&lt;BR /&gt;&lt;BR /&gt;Thanks, in advance.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 01 Sep 2006 09:05:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000903#M47720</guid>
      <dc:creator>Junior C.</dc:creator>
      <dc:date>2006-09-01T09:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: Help:  perl count/sort</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000904#M47721</link>
      <description>The only problem with the following code is that it doesn't sort the date. You'll have to insert a subroutine on the line: "my @dates=sort  keys %hash;" between sort and keys %hash. Let us know if you need more help.&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;open FILE, "path to a file" or die "Couldn't open a file";&lt;BR /&gt;my $lines;&lt;BR /&gt;my %hash;&lt;BR /&gt;while (&lt;FILE&gt;) {&lt;BR /&gt; chomp;&lt;BR /&gt; $lines++;&lt;BR /&gt; $hash{$_}++;&lt;BR /&gt;}&lt;BR /&gt;my @dates=sort  keys %hash;&lt;BR /&gt;for (@dates)&lt;BR /&gt;{&lt;BR /&gt; print $_." : ".$hash{$_}."\n";&lt;BR /&gt;}&lt;BR /&gt;print "Total: $lines.\n";&lt;/FILE&gt;</description>
      <pubDate>Fri, 01 Sep 2006 09:43:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000904#M47721</guid>
      <dc:creator>Alexander Chuzhoy</dc:creator>
      <dc:date>2006-09-01T09:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: Help:  perl count/sort</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000905#M47722</link>
      <description>if file is always sorted it's quite easy.&lt;BR /&gt;&lt;BR /&gt;open (INPUT, @ARGV[0]);&lt;BR /&gt;@lines=&lt;INPUT /&gt;;&lt;BR /&gt;close (INPUT);&lt;BR /&gt;&lt;BR /&gt;#now you have readed all form file in lines array&lt;BR /&gt;$prev_line=@lines[0];&lt;BR /&gt;$act_count=1;&lt;BR /&gt;$total_count=0;&lt;BR /&gt;foreach $line (@lines){&lt;BR /&gt;  total_count++;&lt;BR /&gt;  if ($line eq $prev_line){&lt;BR /&gt;    $act_count++;&lt;BR /&gt;  }&lt;BR /&gt;  else { &lt;BR /&gt;    print "$prev_line : $act_count\n";&lt;BR /&gt;    $perv_line = $line;&lt;BR /&gt;    $act_count=1;&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;print "Total : $total_count\n";&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;it's all and should be OK if there are no blank lines(if there are you should tak care about them).</description>
      <pubDate>Fri, 01 Sep 2006 09:46:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000905#M47722</guid>
      <dc:creator>g33k</dc:creator>
      <dc:date>2006-09-01T09:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: Help:  perl count/sort</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000906#M47723</link>
      <description>anyway best solution is to learne perl yourself here is something for begginers... &lt;A href="http://www.comp.leeds.ac.uk/Perl/start.html" target="_blank"&gt;http://www.comp.leeds.ac.uk/Perl/start.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;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.</description>
      <pubDate>Fri, 01 Sep 2006 09:51:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000906#M47723</guid>
      <dc:creator>g33k</dc:creator>
      <dc:date>2006-09-01T09:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Help:  perl count/sort</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000907#M47724</link>
      <description>AC/g33k,&lt;BR /&gt;&lt;BR /&gt;Thanks for your reply.&lt;BR /&gt;&lt;BR /&gt;I'm new to perl. following are my script.&lt;BR /&gt;&lt;BR /&gt;my $Process_File="test_file.txt";&lt;BR /&gt;&lt;BR /&gt;open(FP,"$Process_File") or die "Could not open $Process_File: $!\n";&lt;BR /&gt;&lt;BR /&gt;while (&lt;FP&gt;) {&lt;BR /&gt;     @words = split ' ';&lt;BR /&gt;   foreach $word (@words) {&lt;BR /&gt;     $count{$word}{$ARGV}++;&lt;BR /&gt;     $count++;&lt;BR /&gt;                          }&lt;BR /&gt;             }&lt;BR /&gt;&lt;BR /&gt;   foreach $word (keys %count) {&lt;BR /&gt;      $down_date = "$word";&lt;BR /&gt;      $tot_count = join(", ",&lt;BR /&gt;            map "$_:   $count{$word}{$_}",&lt;BR /&gt;         sort keys %{$count{$word}});&lt;BR /&gt;         print "$down_date  $tot_count\n"&lt;BR /&gt;                                }&lt;BR /&gt;&lt;BR /&gt;close (FP);&lt;BR /&gt;           print "    \n";&lt;BR /&gt;           print "Total       :   $count\n";&lt;BR /&gt;&lt;BR /&gt;output:&lt;BR /&gt;&lt;BR /&gt;11-AUG-06  : 2&lt;BR /&gt;15-AUG-06  : 4&lt;BR /&gt;07-AUG-06  : 4&lt;BR /&gt;01-AUG-06  : 2&lt;BR /&gt;25-JUL-06  : 2&lt;BR /&gt;10-JUL-06  : 1&lt;BR /&gt;08-JUL-06  : 3&lt;BR /&gt;14-AUG-06  : 8&lt;BR /&gt;05-AUG-06  : 2&lt;BR /&gt;02-AUG-06  : 2&lt;BR /&gt;18-AUG-06  : 3&lt;BR /&gt;09-AUG-06  : 4&lt;BR /&gt;05-JUL-06  : 5&lt;BR /&gt;&lt;BR /&gt;Total      : 42&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Please advise what I'm doing wrong.   I need output sorted by date all JUL the AUG.    AUG    then  SEP   etc......&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;JC.&lt;/FP&gt;</description>
      <pubDate>Fri, 01 Sep 2006 10:30:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000907#M47724</guid>
      <dc:creator>Junior C.</dc:creator>
      <dc:date>2006-09-01T10:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: Help:  perl count/sort</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000908#M47725</link>
      <description>The thing with hash is that its keys are not sorted. If you could put all entries in array instead (assuming that the file you read the info from is sorted), then you could work and assign hash keys/values on array items and also print array items respectively.&lt;BR /&gt;Hope it helps.</description>
      <pubDate>Fri, 01 Sep 2006 10:56:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000908#M47725</guid>
      <dc:creator>Alexander Chuzhoy</dc:creator>
      <dc:date>2006-09-01T10:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: Help:  perl count/sort</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000909#M47726</link>
      <description>To complete what I mean - I've changed my previous code a bit. Now I collect the data into array and then I do all manipulations.&lt;BR /&gt;This assures that the order in which the data was placed in the array remains intact.&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;open FILE, "path_to_file" or die "Couldn't open a file";&lt;BR /&gt;my (@entries,@uniq,%hash,$lines);&lt;BR /&gt;while (&lt;FILE&gt;) {&lt;BR /&gt; chomp; &lt;BR /&gt; $lines++;&lt;BR /&gt; push @entries,$_; #place each in the array&lt;BR /&gt;}&lt;BR /&gt;for (@entries) {&lt;BR /&gt; push @uniq,$_ unless (defined($hash{$_})); #Need to avoid duplicated entries in output.&lt;BR /&gt; $hash{$_}++; #increment the count of duplicated lines.&lt;BR /&gt;}&lt;BR /&gt;print $_." : ".$hash{$_}."\n" for @uniq;&lt;BR /&gt;print "Total: $lines.\n";&lt;BR /&gt;&lt;BR /&gt;Hope it helps.&lt;/FILE&gt;</description>
      <pubDate>Fri, 01 Sep 2006 14:41:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000909#M47726</guid>
      <dc:creator>Alexander Chuzhoy</dc:creator>
      <dc:date>2006-09-01T14:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Help:  perl count/sort</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000910#M47727</link>
      <description>Alexander,&lt;BR /&gt;&lt;BR /&gt;Perfect.  Thanks,  I appreciate all your reply</description>
      <pubDate>Fri, 01 Sep 2006 16:33:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000910#M47727</guid>
      <dc:creator>Junior C.</dc:creator>
      <dc:date>2006-09-01T16:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: Help:  perl count/sort</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000911#M47728</link>
      <description>Thread Close</description>
      <pubDate>Fri, 01 Sep 2006 16:34:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-perl-count-sort/m-p/5000911#M47728</guid>
      <dc:creator>Junior C.</dc:creator>
      <dc:date>2006-09-01T16:34:23Z</dc:date>
    </item>
  </channel>
</rss>

