Ok, are you ready?
How to convert netstat -i | tail -n +3 netstat -i | tail -n +3 to the associative array of the bash array:
declare -A AANET while read -a line ;do declare -a AI$line eval "AI$line=(${line[@]})" AANET[$line]=AI$line done < <( netstat -i | tail -n +3)
Than now:
echo ${!AANET[@]} venet0 eth1 eth0 lo br0 echo ${AANET[eth0]} AIeth0
And for subassociative we should use eval :
eval echo \${${AANET[eth0]}[@]} eth0 1500 0 17647 0 0 0 35426 0 0 0 BMPU eval echo \${${AANET[eth0]}[1]} 1500 eval echo \${${AANET[eth0]}[3]} 17647 eval echo \${${AANET[eth0]}[7]} 35426 eval echo \${${AANET[eth0]}[@]:3:5} 17647 0 0 0 35426
An to define a temporary variable:
eval currentBin=\${${AANET[eth0]}[3]} currentBout=\${${AANET[eth0]}[7]} echo $currentBout 35426 echo $currentBin 17647
or even too much:
eval "declare -a currentVals=(\${${AANET[eth0]}[@]:3:8})" echo ${currentVals[0]} 17647 echo ${currentVals[4]} 35426 echo ${currentVals[@]} 17647 0 0 0 35426 0 0 0
Edit
Well, if possible without eval !
for aKey in ${!AANET[@]};do fields=(${AANET[$aKey]}{[1],[3],[7]}); echo $aKey ${!fields} ${!fields[1]} ${!fields[2]} done | xargs printf "%-9s %12s %12s %12s\n" IFace MTU RX TX IFace MTU RX TX venet0 1500 0 0 eth1 1500 6400292 6942577 eth0 1500 17647 35426 lo 16436 83 83
source share