grep extract substring code example
Example 1: grep for substring
output=$(command)
[[ $output =~ (CpuIowait=[0-9][.][0-9]{2}) ]] && echo "${BASH_REMATCH[1]}"
Example 2: grep extract only matched string
grep -E -o "insert regex here"
output=$(command)
[[ $output =~ (CpuIowait=[0-9][.][0-9]{2}) ]] && echo "${BASH_REMATCH[1]}"
grep -E -o "insert regex here"