On Wed, Feb 3, 2016, at 10:06 AM, Ralph Sims wrote: > > I am trying to parse the results of shell script and am unable to get > the output needed. [skip a bit, brother] > The OID_LIST contains: > 1.3.6.1.4.1.41112.1.4.1.1.4 > 1.3.6.1.4.1.41112.1.4.1.1.7 > > The RTR_LIST contains: > 172.16.100.34 > 172.16.100.35
> The output to RESULT.csv > 172.16.100.34, 5570 > 172.16.100.34, 14100 > 172.16.100.35, 5620 > 172.16.100.35, 14200 > > What I am trying to do is format RESULT.csv as: > 172.16.100.34, 5570, 14100 > 172.16.100.35, 5620, 14200 Okay, what you're going to need is a list of structures. (You *could* cheat and say list[0] is the RTR and the rest are the OID's, which is how it would get stored in memory anyway, but you're still going to need a list of lists.) BASH doesn't do this well. Especially when you're trying to write it as a stream; this is NOT a one-pass operation. You did: for i in $RTR do for n in $oid do echo $i,`$snmp $i $n|cut -f2 -d:` >> $LOG done done Thankfully, your output is text, so I can cheat. (Bash IS good at mucking about with strings, especially aided by newer versions of grep(1) with the -o option... but that's not even necessary here.) for i in $RTR do RESULT=$RTR for i in $oid do RESULT="${RESULT},`$snmp $i $n|cut -f2 -d:`" done echo $RESULT >> $LOG done Essentially, stuff comma-then-next-item onto the end of $RTR until we run out of OID's, then output that line. Hopefully all values are unique, otherwise you're back to square one... Hope this helps, Glenn Glenn Stone (technosha...@liawol.org) Have keyboard, will commute...