Home  |  Linux  | Mysql  | PHP  | XML
From:John W. Krahn Date:Wed May 14 15:36:34 2008
Subject:Re: faster ways than perl?
Richard Lee wrote:
> I am running this command on over 2 gigs worth of lines....
> 
> which one should be faster?
> 
> cut -d'|' -f21 * | sort | uniq -c | sort

With cut the fields are numbered starting at 1.


> perl -F"\|"  -lane 'print $F[21]' * | sort | uniq -c | sort

With perl array indexes are numbered starting at 0.  So do you want to 
sort and compare the 21st field or the 22nd field?


> or is there faster ways to do this on perl?

perl -ne'$d{ ( split /\|/ )[ 20 ] }++ }{ printf "%7d %s\n", $d{ $_ }, $_ 
for sort { $d{ $a } <=> $d{ $b } || $a cmp $b } keys %d' *


John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall
Navigate in group perl.beginners at sever nntp.perl.org
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by PHP Developer
Powered By PHP Consultants