#!/bin/ksh #exponent is 0 if the file is less than 1K. #Otherwise, exponent is 1 if the file is less than 1M. #Otherwise, exponent is 2 if the file is less than 1G. Et cetera. #log($5) / log(1024) is the logarithm of $5 to the base 1024. ls -l | /usr/xpg4/bin/awk ' BEGIN { a[0] = "" a[1] = "K" #kilo a[2] = "M" #mega a[3] = "G" #giga a[4] = "T" #tera a[5] = "P" #peta } NR > 1 && /^-/ { exponent = $5 == 0 ? 0 : int(log($5) / log(1024)) print $5 / 1024^exponent a[exponent] "\t" $NF } ' exit 0