I have a string coming through in the following format:
"Memory Used": "500 MB"
"Memory Used": "768 KB"
Basically, what I need to do is convert everything into MBs in integer/float format. For the fields containing "MB," it's simple enough. I just do a gsub and replace "MB" with "". I'm having a bit of trouble with the fields containing "KB" though. What I need to do is strip off KB if it exists, then divide the new integer by 1000 to get MBs. Any advice?
I'm on my phone. So I won't even try to write working code. But what I'd do is write a ruby filter:
Initialize a variable divisor = 1
If the field value matches .*kb$ divisor = 1000
Replace everything that is not a number [^\d] with nothing (gsub)
Convert the string: Integer()
Divide this by the divisor.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.