Re: faster ways than perl?

[email protected] ("John W. Krahn")
Newsgroups perl.beginners
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.