Say I have the string \"Memory Used: 19.54M\" How would I extract the 19.54 from it? The 19.54 will change frequently so i need to store it in a variable and compare it with
Other possible solutions:
With grep
:
var="Memory Used: 19.54M"
var=`echo "$var" | grep -o "[0-9.]\+"`
With sed
:
var="Memory Used: 19.54M"
var=`echo "$var" | sed 's/.*\ \([0-9\.]\+\).*/\1/g'`
With cut
:
var="Memory Used: 19.54M"
var=`echo "$var" | cut -d ' ' -f 3 | cut -d 'M' -f 1`
With awk
:
var="Memory Used: 19.54M"
var=`echo "$var" | awk -F'[M ]' '{print $4}'`