LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash script to parse Output (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-to-parse-output-4175598393/)

pradeepspa 01-27-2017 02:28 PM

Bash script to parse Output
 
Hello All,

This is my code ,

Code:

#!/bin/bash
Output=` snmpwalk -m /usr/share/snmp/mibs/CISCO-UNIFIED-COMPUTING-STORAGE-MIB.my -v2c -c opennms-Priv x.x.x.x .1.3.6.1.4.1.9.9.719.1.45.4.1.18 2>/dev/null | awk '{print $4}' | while read -r line ; do echo "Drive:$line" ;  done`

printf '%s\n' $Output


For this I am getting output similar to this,

Quote:

Drive online(1)
Drive online(1)
Drive online(1)
Drive online(1)
Drive online(1)

I am trying to modify the code to display like,

Quote:

Drive1 online(1)
Drive2 online(1)
Drive3 online(1)
Drive4 online(1)
Drive5 online(1)

Could someone guide me what needs to be added in code to achieve above result?

szboardstretcher 01-27-2017 02:37 PM

Code:

Output=$(snmpwalk -m /usr/share/snmp/mibs/CISCO-UNIFIED-COMPUTING-STORAGE-MIB.my -v2c -c opennms-Priv x.x.x.x .1.3.6.1.4.1.9.9.719.1.45.4.1.18 2>/dev/null | awk '{print $4}' | let i=1; while read -r line ; do echo "Drive $i:$line"; ((i++)); done)
Something like that?

pradeepspa 01-27-2017 02:44 PM

Thats exactly what i was expecting. Thanks for the quick help. I appreciate it.


All times are GMT -5. The time now is 02:29 PM.