I am reading a file in a loop and there is string i got in each iteration. I need to add this element to array but in new line
i use the blow cmd ARRAYNAME+=$ELEMENTNAME
but what happens thet element is added to the last one but separated by " " instead of lines
while IFS='' read -r line || [[-n "$line" ]];do
MAPPING=`echo $line | grep -e session -e sub | cut -d: -f3 | grep -i ","`
MAPPINGMAT+=("$MAPPING")
echo ${MAPPINGMAT[*]}
done < "$1"
output
1
1 2
1 2 3
but i need it to be
1
2
3
MAPPINGisn't valid I don't think, sincegrep -ineeds a pattern, then you're not appending a full line to your array, and you're telling the loop to print the entire line on a single line in each iteration of the loop. Use theforloop from my answer after the while loop to get it to print each element on its own lineecho $MAPPINGwithin thewhileinstead of printing the whole array each time