The following command format the disk_space_in_bytes
variable into a human readable output, with 2 digits after the comma.
echo $disk_space_in_bytes | awk '{ suffix=" KMGT"; for(i=1; $1>1024 && i < length(suffix); i++) $1/=1024; printf("%.2f\n", $1); print(substr(suffix, i, 1)"B")}'
(Credit goes to @Innocent Bystander https://stackoverflow.com/a/36724130/6133648 for this awk command)
For example if disk_space_in_bytes
is 858 458 685,44
(value in bytes), then the command will print 818.69 MB
, but with a space in between.
I would like to remove this extra space, for example 818,69MB
. But this get a little bit to tricky for me in awk. I tried some ORS and OFS manipulation without success.
Can you find way to remove the extra space ?
Thanks