Created
December 9, 2010 15:26
-
-
Save l0b0/734829 to your computer and use it in GitHub Desktop.
Unformat disk size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Convert strings like '5kb', '2MB' and '500TB' to their byte equivalents | |
# Based on http://stackoverflow.com/questions/4399475/unformat-disk-size-strings | |
unformat() | |
{ | |
echo $1 | sed -e 's/b//i;s/k/*1000/i;s/m/*1000000/i;s/g/*1000000000/i;s/t/*1000000000000/i' | bc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Might want to add a clause for the
i
character, to support the difference between ISO KiB (1024) and KB (1000).