I'd like to convert all number abbreviations such as 1K, 100K, 1M, etc. in a text file into plain numeric values such as 1000, 100000, 1000000, etc.
So for example, if I have the following text file:
1.3K apples 87.9K oranges 156K mangos 541.7K carrots 1.8M potatoes
I would like to convert it to the following in bash:
1300 apples 87900 oranges 156000 mangos 541700 carrots 1800000 potatoes
The command I have used is to replace matching strings of number abbreviations with their full numeric values like so:
sed -e 's/1K/1000/g' -e 's/1M/1000000/g' text-file.txt
My problem is that I cannot find and replace ALL of the possible number abbreviations when variation occurs. I'd like to do this until at least up to one decimal abbreviations.
https://stackoverflow.com/questions/65536137/convert-all-number-abbreviations-to-numeric-values-in-a-text-file January 02, 2021 at 12:58PM
没有评论:
发表评论