I tried generating variables dynamically and assigning values to it but I encountered two issues with the code:
- I am not able to convert the value of "count" to numeric value so it can be used in for loop
- The values of variables are lost after for loop is completed.
Code
filename=$1
count= sed -n 1p $1 | tr ',' '\n' | wc -l
while read line
do
if [ $i -ne 1 ]; then
check_Keyword=`echo $line |grep -Eo '\b,Error\b'`
if [ "$check_Keyword" = ",Error" ]; then
if [ $post_counter -eq 0 ]; then
post_counter=$(expr $post_counter + 1)
else
write_values
fi
temp_text=""
for j in $(eval echo {1..count} )
do
Column[$j]=`echo $line | cut -d ',' -f$j`
done
temp_text=`echo $line | cut -d ',' -f3`
else
temp_text=$line
fi
msg_identifier=$msg_identifier$temp_text
fi
i=$(expr $i + 1)
done < $file_name