Helpful Information
 
 
Category: UNIX Help
String functions with BASH scripting

I'm having trouble getting into the scripting for BASH, this typeless variables are really confusing me sometimes.

For example, i am trying to generate a string address that i can wget. I use the following code:

for i in `seq 1997 2003`; do
for j in `seq 1 12`; do
for k in `seq 1 31`; do
wget http://www.somedomain.com/$i$j$k.txt
done
done
done

Unfortunately, the web server i am trying to connect to has it's files arranged in this format:
yyyymmdd - which means that mm or dd may contain a leading zero.
I was wondering how could you check if $j and $k are only one character long and append a zero to it?

Thanks for any help in advanced :)

j=`printf '%.02d' $j`

;)

Thanks a lot, it works :)
However, there is a little problem... the file im trying to wget is a series, and it starts on 1997, 9th of Augest.

Im not sure if i understand the looping commands at the beginning, but when i do this:

for j in `seq 8 12`; do
for k in `seq 9 31`; do

// blah bah

done
done

when it has finished trying to get 19970809, it will then go to 19970010 :(

what am i doing wrong?

this sounds quite complicated to do with loops. and i donīt have this "seq" command installed on any of my boxes, so i canīt look up the man pages either. does it also work eg. like this?

for i in `seq 01/01/2001 12/31/2002`

if not, sorry, i donīt have an out-of-the-box solution for you. you need to make up some logic like:
- first get the remaining days of the first month
- then get the remaining months of the first year
- then start over with 01/01 of the next year
....










privacy (GDPR)