-1

How to parse the string output

5 Secs ( 2.2889%) 60 Secs ( 2.5874%) 300 Secs ( 2.6215%)    

to take only 2.6215

3 Answers3

1

Using grep and lookbehind/lookahead:

grep -Po "(?<=Secs \( )[0-9.]*(?=%\)$)"

Using sed:

sed 's/.*Secs ([[:space:]]*\([0-9.]*\)%)$/\1/g'
aviro
  • 144
  • 4
0

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.

Phill W.
  • 1,479
  • 7
  • 7
0

Personally I'm a "keep it simple" kind of guy:

./command | awk '{print $12}' | sed 's/%)//'
serverguy
  • 11
  • 3