#!/bin/bash declare -A circuits declare -A streams while read l; do id=$(echo $l|grep -Po '^\d+') circ=$(echo $l \ | grep -Po '[^ ]*$' \ | sed 's/,/ /g' \ | tr -d "\r") #echo $id ++ ${circ[@]} circuits[$id]=$circ done <<< $( { nc 127.0.0.1 9051 < ${circuits[$key]}" done