libertyforall2
asked on
create 12 month binned averages using shell script
I want to create a 12 month binned or rolling average to help smooth the data. I currently have monthly averages in the file. Since a 12 month rolling average needs 12 months of course, the first 11 rows will not have a binned average. I would prefer to create a separate output file with a 3 column for the binned average next to the corresponding YYYYMM. I could then create a graph showing the monthly data alongside the smoothed binned average.
avgs.txt
avgs.txt
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I removed the shebang I get this message
maverages.sh: line 6: ` read date average < <(echo $line)'
uila%
maverages.sh: line 6: ` read date average < <(echo $line)'
uila%
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok. It worked but I wanted to keep the first 11 rows with only 2 columns instead of deleting them. it would be 3 columns from row 12 and after.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works. Thanks.
ASKER
#!/bin/ksh
>moving-avgs.txt
while read line
do
read date average < <(echo $line)
qty[$i]=$average
[[ i -ge 11 ]] && {
addlist=$(echo ${qty[@]:$((i-11)):$i} | sed 's/ /+/g')
avg=$(echo "scale=2;($addlist)/12" | bc)
echo $date $average $avg >> /home/uila3/rhuff/msstate/
}
((i++))
done < /home/uila3/rhuff/msstate/
</code>
uila% sh maverages.sh > /home/uila3/rhuff/msstate/
maverages.sh: line 6: syntax error near unexpected token `<'
maverages.sh: line 6: ` read date average < <(echo $line)'
uila%