Divide variable

Hi All,

here D Prints the bytes value .plz help to convert the variable D value to MB in new variable $E

D=`more $C |awk '{print $6;}'`

Thanks in Advance.:slight_smile:

E=$( echo $D | awk '{ printf "%.2f", $0/1073741824; } ' )

If formatting is not important.

E$=$(awk '{print $0/1073741824}' <<< $D)

@bipinajith
The semicolon ; after 4 is not strictly needed?

E=$( echo $D | awk '{print $1/2^20}' )
E=$( echo $D | awk '{$1/=2^20}1' )

Alternative:

E=$( echo "$D/2^20" | bc -l )

ksh93:

E=$(( D/2**20.0 ))

Bash/ksh is you do not care about the precision:

E=$(( D/2**20 ))

Any POSIX shell if you do not care about the precision:

E=$(( D >> 20 ))

--
MiB, not GiB
The trailing semicolon in awk is superfluous indeed