Anonymous user
File size distribution: Difference between revisions
UNIX shell: further simplification, only need one awk invocation
(UNIX shell: fix wrong sort for files more than 1GB and "prettyfy" the output) |
(UNIX shell: further simplification, only need one awk invocation) |
||
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
if [ ${GNU:-} ]
then
else
fi | awk -vOFS='\t' '
{
}
max = -2
for (i in hist)▼
max = (i > max ? i : max)
for (i = -1; i <= max; ++i)
▲ tabs -8
{
{
▲ split("KB MB GB TB PB", u); u[0] = "B"
if (i == -1)
▲ print "From", "To", "Count\n"
print "0B", "0B", hist[i]
else
print 10 ** (i % 3) u[int(i / 3)],
}
}
▲ 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
|