I have a command that outputs multiple lines -
echo status | nc localhost 5555 | grep "^CLIENT_LIST"
Results in -
CLIENT_LIST,unitthree,0.0.0.0:51842,10.8.0.103,,1722129,1719487,Mon May 11 09:20:49 2020,1589206849,UNDEF,460,1
CLIENT_LIST,pietwo,0.0.0.0:37302,10.8.0.52,,32277793,32154811,Thu Apr 16 07:33:57 2020,1587040437,UNDEF,376,0
CLIENT_LIST,pieone,0.0.0.0:30301,10.8.0.51,,40357177,41921529,Fri Apr 10 13:37:07 2020,1586543827,UNDEF,345,3
CLIENT_LIST,jeremy,0.0.0.0:65217,10.8.0.45,,21895323,75146681,Fri May 15 08:31:27 2020,1589549487,UNDEF,497,2
CLIENT_LIST,officepi,0.0.0.0:38596,10.8.0.40,,13051,12267,Fri May 15 08:46:47 2020,1589550407,UNDEF,503,5
Now, I want to put that in a more readable format so I wrote this script -
#!/bin/bash
command="$(echo status | nc localhost 5555 | grep "^CLIENT_LIST")"
IFS='
'
read -a list <<< "$command"
IFS=','
for line in "${list[@]}"
do
read -a item <<< "$line"
echo ${item[1]} - ${item[3]} Since ${item[7]}
done
The output is only the first line -
unitthree - 10.8.0.103 Since Mon May 11 09:20:49 2020
What am I doing wrong? When I echo just $command I get only the last line. I'm confused. How do I get the output of the command as one variable, or an array of variables, one for each line? Looks like the last part of the script works fine extracting the info from the line. Thanks!