Anonymous user
File size distribution: Difference between revisions
UNIX shell: fix wrong sort for files more than 1GB and "prettyfy" the output
(Simplify and accelerate UNIX shell solution massively) |
(UNIX shell: fix wrong sort for files more than 1GB and "prettyfy" the output) |
||
Line 1,605:
{{works with|Bourne Shell}}
Use POSIX conformant code unless the environment variable GNU is set to anything not empty.
<lang sh>
#!/bin/sh
set -eu
#!/bin/sh
set -eu
if [ ${GNU:-} ]
then
else
fi | awk '
{
}
print total, NR
print i, hist[i]
{
read total
tabs -8
sort -n | awk -vtotal="$total" -vOFS='\t' '
BEGIN {
split("KB MB GB TB PB", u); u[0] = "B"
print "From", "To", "Count\n"
}
$1 == -1 {print "0B", "0B", $2; next}
{
print 10 ** ($1 % 3) u[int($1 / 3)],
10 ** (($1 + 1) % 3) u[int(($1 + 1) / 3)],
$2
}
END {
$0 = total
l = length($1) - 1
printf "\nTotal: %.1f %s in %d files\n",
$1 / (10 ** l), u[int(l / 3)], $2}'
}</lang>
{{out}}
<pre>$ time ~/fsd.sh
100MB 1GB 5056
Total: 612404756079 bytes in 85850 files▼
1GB 10GB 1139
~/fsd.sh 0.60s user 0.98s system 134% cpu 1.182 total▼
10GB 100GB 141
100GB 1TB 1
$ time GNU=1 ~/fsd.sh
100MB 1GB 5056
Total: 612404756079 bytes in 85850 files▼
1GB 10GB 1139
GNU=1 ~/fsd.sh 0.35s user 0.48s system 135% cpu 0.613 total</pre>▼
10GB 100GB 141
100GB 1TB 1
=={{header|zkl}}==
|