for loop (001 to 500)


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers for loop (001 to 500)
# 1  
Old 12-28-2011
for loop (001 to 500)

hey,
how do i create a for loop that runs for i from 001 to 500 ?
i need that the zero prefix will remain so when i print "i" it will
look like so:

Code:
001
002
 .
 .
008
009
  . 
  .
058
059
  .
  .
500

please advise.
thank u for your much appreciated help.
# 2  
Old 12-28-2011
Code:
$ i=1; while [ $i -le 500 ]; do printf "%03d\n" $i ; i=$((i+1)); done

This User Gave Thanks to jayan_jay For This Post:
# 3  
Old 12-28-2011
Code:
 
man seq

see the -w option

---------- Post updated at 03:19 PM ---------- Previous update was at 03:14 PM ----------

i guess it should be

Code:
 
seq -w 001 500

This User Gave Thanks to itkamaraj For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

System call failed with 127 .. after 500 times when called in loop

Hi Experts, I have a code like this. ===== #include.... int main() { int count = 0; while(1){ printf("\n Interation number is: %d \n ",count); rv = system(" test.sh > log.txt " ); if (-1 == rv) { printf("Could not generate static log: error... (12 Replies)
Discussion started by: binnyjeshan
12 Replies

2. Shell Programming and Scripting

Fill the values between -500 to 500 -awk

input -200 2.4 0 2.6 30 2.8 output -500 0 -499 0 -488 0 .......... .......... .... -200 2.4 .... ... 0 2.6 (6 Replies)
Discussion started by: quincyjones
6 Replies

3. Shell Programming and Scripting

How can get the value 001 using shell script

Hi Gurus, Please help in this shell script. x=000 y=`expr $x + 1` echo $y which gives me the value as 1 How can i get the value as 001 in this shell script. As i am new to scripting stuck up here. Requesting here help here (2 Replies)
Discussion started by: nmadhuhb
2 Replies
Login or Register to Ask a Question