How to parse the string output
5 Secs ( 2.2889%) 60 Secs ( 2.5874%) 300 Secs ( 2.6215%)
to take only 2.6215
How to parse the string output
5 Secs ( 2.2889%) 60 Secs ( 2.5874%) 300 Secs ( 2.6215%)
to take only 2.6215
Using grep and lookbehind/lookahead:
grep -Po "(?<=Secs \( )[0-9.]*(?=%\)$)"
Using sed:
sed 's/.*Secs ([[:space:]]*\([0-9.]*\)%)$/\1/g'
Assuming you're using bash, something like this?
PATTERN="(\d+\.\d{4})%\)$"
if [[ "${VALUE}" =~ ${PATTERN} ]] ; then
VALUE="${BASH_REMATCH[1]}"
fi
Reworked from this Stack Overflow post.
Personally I'm a "keep it simple" kind of guy:
./command | awk '{print $12}' | sed 's/%)//'