How i print specific information on Bash

51 views Asked by At
#!/bin/bash

echo "Digite o IP"
read ip

iod= snmpwalk -v2c -c public "$ip":161 .1.3.6.1.2.1.1.5

echo "$iod"

OUTPUT

iso.3.6.1.2.1.1.5.0 = STRING: "Name"

I want just print the "name", I'm kinda new on bash scripting. I apreciate an hand. Thakyou.

1

There are 1 answers

0
James Risner On

Use sed:

#!/bin/bash
echo "Digite o IP"
read ip
iod= snmpwalk -v2c -c public "$ip":161 .1.3.6.1.2.1.1.5
echo "$iod" | sed -e 's/^.*STRING: //'

This outputs just "Name" with the supplied data. We use sed to remove anything before the "STRING: " including the search string itself.

echo 'iso.3.6.1.2.1.1.5.0 = STRING: "Name"'  | sed -e 's/^.*STRING: //'
"Name"