I have a small piece of code that I need to iterate 24 times (for each hour of a day).... here's what it looks like now...
Code:
while read hour file; do
if [ $hour -eq 00 ]; then
count=`awk -F, 'BEGIN { count=0 } ............. { count++ } END { print count }' $file`
hourly01=`expr $hourly1 + $trade_count`
elif [ $hour -eq 01 ]; then
count=`awk -F, 'BEGIN { count=0 } ............. { count++ } END { print count }' $file`
hourly02=`expr $hourly2 + $trade_count`
..................
fi
done < ls.txt
As you can see it's simple, and iterates over and over, but unneccessarily (24 times)... Could I replace all the numbers with one variable... like such..
don't take my code letter for letter, just take the idea and tell me if it can be done..
Code:
for (x=00; x<=23; x++) {
if [ $hour -eq $x ]; then
count=`awk -F, 'BEGIN { count=0 } ............. { count++ } END { print count }' $file`
hourly$x=`expr ${hourly}$x + $trade_count`
fi
}
Thats' the idea.. I know that I didn't use a unix
for-loop, but I just started learning unix and I didn't check what the for looks like in unix yet).. But can I write the middle section (every occurence of $x) the way that I wrote it here?