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
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2008
Registered User
 

Join Date: Feb 2007
Posts: 37
Sort and Unique in Perl

Hi,

May I know, if a pipe separated File is large, what is the best method to calculate the unique row count of 3rd column and get a list of unique value of the 3rdcolum?

Thanks in advance!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-08-2008
Registered User
 

Join Date: Jan 2008
Posts: 294
read the file line by line and use a hash to get the unique values of the 3rd column.
Reply With Quote
  #3 (permalink)  
Old 02-08-2008
Registered User
 

Join Date: Feb 2007
Posts: 37
Quote:
Originally Posted by KevinADC View Post
read the file line by line and use a hash to get the unique values of the 3rd column.
Could you kindly explain with one simple example.
Reply With Quote
  #4 (permalink)  
Old 02-08-2008
Registered User
 

Join Date: Feb 2008
Location: The Netherlands
Posts: 38
Maybe realy simple:

cat $file|awk -F\| '{print $3}'|sort -u

(I think some awk guru can do it with less commands)...

I saw to late you meant perl.. sorry
Reply With Quote
  #5 (permalink)  
Old 02-08-2008
Registered User
 

Join Date: Feb 2007
Posts: 37
Quote:
Originally Posted by rvegmond View Post
Maybe realy simple:

cat $file|awk -F\| '{print $3}'|sort -u

(I think some awk guru can do it with less commands)...
I can handle with cut, sort -u, and wc commands.

But looking for perl methods!
Reply With Quote
  #6 (permalink)  
Old 02-08-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,442
read the file
split the record
use the third field
populate in a hash => this would maintain uniqueness
when displaying use sort keys %hash
Reply With Quote
  #7 (permalink)  
Old 02-08-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,442
Quote:
Originally Posted by rvegmond View Post
Maybe realy simple:

cat $file|awk -F\| '{print $3}'|sort -u

(I think some awk guru can do it with less commands)...

I saw to late you meant perl.. sorry
Code:
awk -F"|" '{ print $3 }' file | sort -u
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:31 AM.


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

Content Relevant URLs by vBSEO 3.2.0