grep for substring 1

grep for substring

output=$(command)
[[ $output =~ (CpuIowait=[0-9][.][0-9]{2}) ]] && echo "${BASH_REMATCH[1]}"

Here is what the above code is Doing:
1. The first line is a regular expression that matches the string “CpuIowait=0.00”
2. The second line is a command that outputs a string that contains the string “CpuIowait=0.00”
3. The third line is a command that runs the command in the second line and stores the output in the variable output
4. The fourth line is a conditional statement that checks if the variable output contains the regular expression in the first line
5. The fifth line is a command that prints the first match of the regular expression in the first line

Similar Posts