How can I convert bytes to gigabytes in each line in single column in Bash? I have tried this:
echo "scale=2; $(cat file.log) / 1024^2" | bc
but that convert only last value.
Example of file.log content:
2171863040
1693491200
1984045056
(without spaces between)
You could use awk:
$ cat file.log
1073741824 1073741824
$ awk '{print $1/1024/1024/1024 " GB " $2/1024/1024/1024 " GB"}' file.log
1 GB 1 GB
or using the sample data you just posted:
$ awk '{print $1/1024/1024/1024 " GB "}' file.log
2.02271 GB
1.57719 GB
1.84779 GB
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With