I have a list of users like below and I would like to convert the units to gigabytes
user1@example.com Mbox size: 7445440 Kb
user2@example.com Mbox size: 6622275 Kb
user3@example.com Mbox size: 4657973 Kb
user"n"@example.com Mbox size: 3657673 Kb
Any help would be appreciated.
For calculations I like to use awk embedded in bash scripts.
Save the script below to a file, e.g. togb.sh and make it executable. If you need decimals, just adapt the printf format.
Store your data in a file data.txt and call the script using the commandline:
To display the list in the same format but with changed units, you would use this slightly changed script:
The output of this script would be:
By the way, awk can do much more than this, it’s in fact ideal for processing data stored in text files.