0

i have the following SNMP Command

snmpget -v 1 -c COMMUNITY -t 2 HOST:161  1.3.6.1.4.1.24681.1.2.1.0 | awk '{print $4 $4}' | sed 's/.\(.*\)...../\1/'

that returns a string

9.10

what is percent value in the worng decimal.

I want to multiplicate this with 10 to make it correct:

91.0

How can I do this with the command above?

Thanks! John


The snmpget command outputs the string

iso.3.6.1.4.1.24681.1.2.1.0 = STRING: "9.10 %"
AdminBee
  • 22,803

1 Answers1

1

Use one awk command like this:

# Use two sepatators, <space> and ", so you catch exactly the number.
# Multiply by 10
# `printf` allows you to format numbers in many ways, in this case, 1 decimal

str='iso.3.6.1.4.1.24681.1.2.1.0 = STRING: "9.10 %"'

$ echo "$str" | awk -F'[ "]' '{ printf "%.1f\n", $5*10 }' 91.0

Or as pointed out by @Stéphane Chazelas, this works too:

echo "$str" | awk -F \" '{ printf "%.1f\n", $2*10 }'

Modifiers for printf Formats

%e, %E, %f, %F
Number of digits to the right of the decimal point.`