The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-08-2008
deepakwins deepakwins is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 39
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!
  #2 (permalink)  
Old 02-08-2008
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

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

Join Date: Feb 2007
Posts: 39
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.
  #4 (permalink)  
Old 02-08-2008
rvegmond rvegmond is offline
Registered User
  
 

Join Date: Feb 2008
Location: The Netherlands
Posts: 39
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
  #5 (permalink)  
Old 02-08-2008
deepakwins deepakwins is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 39
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!
  #6 (permalink)  
Old 02-08-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
read the file
split the record
use the third field
populate in a hash => this would maintain uniqueness
when displaying use sort keys %hash
  #7 (permalink)  
Old 02-08-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0