I have below code and I want to get daily_balue, monthly_value, priorday_value, priorweek_value, priormonth_value from log file. As per the code the daily_value, monthly value, priorday value, prior week and priormonth value are stored in first index of array.
How to get daily,monthly value priority prior week and prior month values from first index of array ?
sql file as shown below:
first input file columns order:
cash , monthly_value, null,null, 0.000
cash, daily_value,2022-02-22,2022-02-22,3
cash, priormonth_value,2022-02-22,2022-02,8
cash , priorday_value, null,null, 10
cash, priorweek_value,2022-02-22,2022-02-22,32
loans, monthly_value, 2022-02-22,2022-02-22, 21.000
loans, daily_value,2022-02-22,2022-02-22,4
loans,priormonth_value,2022-02-22,2022-02,9
loans , priorday_value, null,null, 12
loans,priorweek_value,2022-02-22,2022-02-22,23
Output for first input should be stored in the below format in a csv file format : $date, $row, $daily_balue, $monthly_value, $priorday_value, $priorweek_value, priormonth_value
2022-02-22, cash, 3, 0.00, 10, 32, 8
2022-02-22, loans, 4, 21.00, 12, 23, 9
In some case the priormonth_values might be missing, so need to add zero in the output file second input file columns order:
cash , monthly_value, null,null, 0.000
cash, daily_value,2022-02-22,2022-02-22,3
cash , priorday_value, null,null, 10
cash, priorweek_value,2022-02-22,2022-02-22,32
loans, monthly_value, 2022-02-22,2022-02-22, 21.000
loans, daily_value,2022-02-22,2022-02-22,4
loans , priorday_value, null,null, 12
loans,priorweek_value,2022-02-22,2022-02-22,23
Output for second input should be stored in the below format in a csv file format : $date, $row, $daily_balue, $monthly_vale, $priorday_value, $priorweek_value, priormonth_value
2022-02-22, cash, 3, 0.00, 10, 32, 0
2022-02-22, loans, 4, 21.00, 12, 23, 0
third input file columns order . here daily_value and monthly_value are missing from the file
cash, priormonth_value,2022-02-22,2022-02,8
cash , priorday_value, null,null, 10
cash, priorweek_value,2022-02-22,2022-02-22,32
loans,priormonth_value,2022-02-22,2022-02,9
loans , priorday_value, null,null, 12
loans, priorweek_value,2022-02-22, 2022-02-02,11
Output for third input should be stored in the below format in a csv file. daily_value and monthly_value are assigned 0 format : $date, $row, $daily_balue, $monthly_vale, $priorday_value, $priorweek_value, priormonth_value
2022-02-22, cash, 0, 0, 10, 32, 8
2022-02-22, loans, 0, 0, 12, 11, 9
declare -A arr
if [ -s $sqlfile ]
then
while IFS=, read key value; do
arr[$key] = "${arr[$key]}$arr[$key]:+,}$value"
done < $sqlfile
i=0
for key in "${!arr[@]}"; do
row=`echo $key | xargs`
values = ${arr[$key]}
daily_value = `echo $values | cut -d ',' -f8 | xargs`
priomonth_value = `echo $value | cut -d ',' -f12 | xargs`
i = $((i+1))
done
else
echo "$sqlfile is empty"
fi
exit 0