Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counter in shell script

Status
Not open for further replies.
Jun 3, 2007
84
US
Hello,

wondering how I would go about doing this. I have a script that searches logs based on a date range of sdate and edate. The script work for the most part, except when the date has a 0 (zero) in the date field. For example when running the script if a sdate of 20080501 and edate of 20080515 is passed with the script, when the script counts up from the day 01 to 15 it removes the 0 in 01-09 printing it as 1,2,3,4,5,6,7,8,9 instead of 01,02,03,04,05,06. I was wondering what the best way would be to fix that.


Code:
sample code

begin_date=`echo $strd |cut -c5-6` #this will output start day
end_date=`echo $etrd |cut -c5-6` #this will output end day

until [ -eq  ]
do
    let "begin_date=$begin_date + 1" #doing this removes the 0 from 01,02,03 etc.

Is there anyway to force the count or add the zero to only the 01-09 entries?

thanks for help

 
[tt]typeset -Z2 var
var=1
echo ${var}[/tt]

produces "01"


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top