Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#!/bin/ksh
# # #
# convert B/K/M/G/T/P
# byte
# kilobyte
# megabyte
# gigabyte
# terabyte
# petabyte
# # #
# parameters
value=$1
req_unit=$2
echo ${value} ${req_unit}|\
tr '[A-Z]' '[a-z]'|\
awk 'BEGIN {
B=1
K=1024
M=1024*K
G=1024*M
T=1024*G
P=1024*T
}
{
value_unit=substr($1,length($1),1)
value_size=substr($1,1,length($1)-1)
if (value_unit=="k") value_size*=K
if (value_unit=="m") value_size*=M
if (value_unit=="g") value_size*=G
if (value_unit=="t") value_size*=T
if (value_unit=="p") value_size*=P
if ((value_unit>="0")&&(value_unit<="9")) value_size=$1
if ($2=="k") printf "%.1f KB\n", value_size/K
if ($2=="m") printf "%.1f MB\n", value_size/M
if ($2=="g") printf "%.1f GB\n", value_size/G
if ($2=="t") printf "%.1f TB\n", value_size/T
if ($2=="p") printf "%.1f PB\n", value_size/P
}'
#! /usr/bin/awk -f
BEGIN {
split("k m g t p",m)
m[0]=""
for (i in m) m[m[i]]=i
print ARGV[1]*1024^m[ARGV[2]]/1024^m[ARGV[3]]
}
'' ( nothing ) = bytes, k = kilobytes, m = megabytes ...Mag0007 said:But what about the byte to kilobyte part?
[blue]master #[/blue] kilo.awk 2005 '' k
1.95801
#! /usr/bin/awk -f
BEGIN {
split("k m g t p e z y",m)
for (i in m) m[m[i]]=i
print ARGV[1] " " ARGV[2] "b = " ARGV[1]*1024^m[ARGV[2]]/1024^m[ARGV[3]] " " ARGV[3] "b"
}
[blue]master #[/blue] kilo.awk 2005 '' k
2005 b = 1.95801 kb
function b(u) { return 1024^index("kmgtpezy",u) }
BEGIN {
print ARGV[1],ARGV[2] " = " ARGV[1]*b(ARGV[2]) / b(ARGV[3]),
ARGV[3]
}