in reply to Rosetta Code: Long List is Long
In awk(1) + sort(1) (environment) ...
#!/bin/sh # Source: https://perlmonks.org/index.pl?node_id=11148773 # # This is one shell implementation based on the problem specification +... # # Rosetta Code: Long List is Long, 20221130, # by eyepopslikeamosquito # https://perlmonks.org/?node_id=11148465 case $# in 0 ) printf "Give a list of files to sort.\n" >&2 exit 1 ;; esac start=$( date '+%s' ) # Takes ~135 s. awk ' \ { cat_count[ $1 ] += $2 } \ END \ { for ( cat in cat_count ) \ { printf "%s\t%s\n", cat, cat_count[ cat ] } \ } \ ' $@ \ | sort -k2,2rn -k1,1 end=$( date '+%s' ) printf "total time: %d s\n" $(( end - start )) >&2
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Rosetta Code: Long List is Long :awk(1)+sort(1)
by marioroy (Prior) on Dec 12, 2022 at 13:47 UTC | |
by parv (Parson) on Dec 12, 2022 at 18:43 UTC |