I am getting some values from a file and putting them in an array..but the null strings are not getting passed to the array. So during printing the elements ,the null string is not showing in the output. during array size calculation it is also excluding null.Please let me know how to do it.
As noted earlier, the arr=( ... ) construct discards leading and trailing space and the expansion of the variable also squeezes whitespace, and the empty fields are no longer recognised as fields during array assignment
Try this alternative instead (using your own awk approaches):
i=0
while IFS= read -r line
do
setnamearr[i++]=$line
done< <(awk '/saveset name:/ {for(i=3;i<=NF;i++) {gsub("\"",""); printf( "%s ", $i )}; printf( "\n"); }' testlog | awk -F ";" '{print $1}')
--
Note: The awk constructs will also squeeze spaces, so that would need some work as well
--
You could try this alternate approach using only bash shell:
i=0
while IFS=':;' read -r label val dummy
do
if [[ $label == *"saveset name" ]]; then
setnamearr[i++]=${val# }
fi
done < testlog