The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unique sort contents of a variable praveenbvarrier Shell Programming and Scripting 2 05-20-2008 04:12 AM
how to sort, and count unique data all at once? amatuer_lee_3 Shell Programming and Scripting 13 05-15-2008 07:48 AM
sort function in perl DILEEP410 Shell Programming and Scripting 2 09-14-2007 05:03 AM
sort and uniq in perl reggiej Shell Programming and Scripting 4 05-18-2006 07:46 PM
Sort file in perl annececile Shell Programming and Scripting 4 06-21-2002 05:52 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #15  
Old 02-08-2008
Registered User
 

Join Date: Feb 2007
Posts: 38
Sorry it was typo in my code. It worked by declaring it earliar.
Thanks!
Reply With Quote
Forum Sponsor
  #16  
Old 02-08-2008
Registered User
 

Join Date: Feb 2007
Posts: 38
One more silly doubt. How to get max value of the %list.
And if I include another field to the existing hash key, will it be composite or individual.
Say I want to find max of arr[2] and need to find the unique and count of list of arr[1], is there a way to use same hash?
Of its suggested to use different has variable?

Thanks.
Reply With Quote
  #17  
Old 02-08-2008
Registered User
 

Join Date: Jan 2008
Posts: 328
Quote:
Originally Posted by deepakwins View Post
One more silly doubt. How to get max value of the %list.
And if I include another field to the existing hash key, will it be composite or individual.
Say I want to find max of arr[2] and need to find the unique and count of list of arr[1], is there a way to use same hash?
Of its suggested to use different has variable?

Thanks.
To find the max value (the highest count I assume) the easiest thing would be to sort the hash by the values:

Code:
@sorted = sort { $list{$a} <=> $list{$b} } keys %list;
print $sorted[-1];
It depends on how you "include" another field into the hash, by field I assume you mean a hash key with a value. Keep in mind that perl hashes do not have indices like perl arrays, there is no such thing as hash[2]. Hashes are not ordered lists like arrays are.
Reply With Quote
  #18  
Old 02-11-2008
Registered User
 

Join Date: Feb 2007
Posts: 38
Thanks for your input.

Here is my requirement.

I need to find max of a date field, which is in 2nd field. And I need to get Unique value of 5th field (Item no) and I need to get number of unique item in 5th field.

Pls help.
Reply With Quote
  #19  
Old 02-11-2008
Registered User
 

Join Date: Jan 2008
Posts: 328
post some lines of the data you are parsing, and show what the results are you want from those lines.
Reply With Quote
  #20  
Old 02-11-2008
Registered User
 

Join Date: Feb 2007
Posts: 38
Thanks for the reply.
Here is the example of the input file.
Code:
26|2007-04-16|76
26|2007-04-18|81
26|2007-04-19|70
26|2007-04-20|84
26|2007-04-21|75
26|2007-04-22|57
26|2007-04-16|109
26|2007-04-18|114
26|2007-04-19|129
26|2007-04-20|157
I want the result to be

Code:
Max Date	Item No	Total Count of Item
2007-04-22	109	10
2007-04-22	114	10
2007-04-22	129	10
2007-04-22	157	10
2007-04-22	57	10
2007-04-22	70	10
2007-04-22	75	10
2007-04-22	76	10
2007-04-22	81	10
2007-04-22	84	10
Right now, iam storing the item no in hash, and during that, manually checking the max date condition using If ($CurrentDate > $MaxDate).... logic.
And Iam getting the total count like
Code:
my $TotalRows = keys(%fileHash1)
Let me know if, other simple effecient method is avaialble.

Thanks in advance.
Reply With Quote
  #21  
Old 02-11-2008
Registered User
 

Join Date: Jan 2008
Posts: 328
sorry, I do not understand the results you want from the data you posted. You will need to explain better how you arrive at those results based on that input. There isn't even a 5th field in the data you posted:

Quote:
And I need to get Unique value of 5th field (Item no)
It's a piped delimited file with 3 fields.

This looks wrong:

$CurrentDate > $MaxDate)

what is the values of $CurrentDate and $MaxDate when you try and compare them like that?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0