# Weekly statistics using while loop.

**URL:** <https://community.unix.com/t/weekly-statistics-using-while-loop/172422>\
**Category:** Shell Programming and Scripting\
**Created:** [June 27, 2007, 2:06am UTC](https://community.unix.com/t/weekly-statistics-using-while-loop/172422 "2007-06-27T02:06:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![filthymonk](https://community.unix.com/letter_avatar/filthymonk/32/6_449c533f586939b6e5f246632a46421f.png) [@filthymonk](https://community.unix.com/u/filthymonk)\
**Post date:** [June 27, 2007, 2:06am UTC](https://community.unix.com/t/weekly-statistics-using-while-loop/172422/1 "2007-06-27T02:06:53Z")

</div>

Hi people i have a situation here: my server generates a statistics text file every 30 mins. i have a script (txt2csv.sh) to convert all the statistics for the day into one csv file. Therefore i am doing a script to auto converts the text files into csv base on a weekly basis.  
the script is suppose to be run using this command :  
./wklystats 06 11 #base on mm dd  
then it should generate a csv for a day one at a time and increase the date numbering by one and generate another csv file until the loop is completed.

```nohighlight
#!/bin/sh

SCRIPTNAME=`basename $0`

show_help ()
{
    echo "Usage: $SCRIPTNAME [input month, mm] [input day, dd]"
    echo "This file is used to generate weekly statistics"
    echo ""
}

if [$# != 2]; then
    show_help
    exit 1
fi

dateday=${2}
inputname="statistics-2007"${1}$dateday"-*"
outputname="statistics-2007"${1}$dateday".csv"

i=1
while [$i -le 7]
do

        ./txt2csv.sh $inputname $outputname
        dateday=$(( dateday + 1))
        i=$(( i+1))

done

```

---

<div class="post-metadata">

**Author:** ![aigles](https://community.unix.com/user_avatar/community.unix.com/aigles/32/118_2.png) [@aigles](https://community.unix.com/u/aigles)\
**Post date:** [June 27, 2007, 3:28am UTC](https://community.unix.com/t/weekly-statistics-using-while-loop/172422/2 "2007-06-27T03:28:42Z")

</div>

No question, no answer.

---

<div class="post-metadata">

**Author:** ![filthymonk](https://community.unix.com/letter_avatar/filthymonk/32/6_449c533f586939b6e5f246632a46421f.png) [@filthymonk](https://community.unix.com/u/filthymonk)\
**Post date:** [June 27, 2007, 3:36am UTC](https://community.unix.com/t/weekly-statistics-using-while-loop/172422/3 "2007-06-27T03:36:08Z")

</div>

hmmm.. sorry

anyway my code is not working its is not adding up the date producing the right output.

---

<div class="post-metadata">

**Author:** ![aigles](https://community.unix.com/user_avatar/community.unix.com/aigles/32/118_2.png) [@aigles](https://community.unix.com/u/aigles)\
**Post date:** [June 27, 2007, 3:52am UTC](https://community.unix.com/t/weekly-statistics-using-while-loop/172422/4 "2007-06-27T03:52:14Z")

</div>

For the date calculation problem, read this thead [Yesterdays Date/Date Arithmetic](http://www.unix.com/answers-to-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html?highlight=datecalc)

---

<div class="post-metadata">

**Author:** ![filthymonk](https://community.unix.com/letter_avatar/filthymonk/32/6_449c533f586939b6e5f246632a46421f.png) [@filthymonk](https://community.unix.com/u/filthymonk)\
**Post date:** [June 27, 2007, 4:19am UTC](https://community.unix.com/t/weekly-statistics-using-while-loop/172422/5 "2007-06-27T04:19:36Z")

</div>

Thanks aigles
