Reputation: 1702
I need to count from number N1 until N2 with Increments of 100 For example
46500 to 49999 Increments of 100
Will print the following
46600
46700
46800
46900
47000
.
.
.
49900
Please advice how to implement (print) this counting with bash
Upvotes: 1
Views: 1491
Reputation: 185434
(for the increment part) :
printf '%s\n' {46500..49999..100}
46500
46600
46700
46800
46900
47000
47100
47200
47300
(...)
49300
49400
49500
49600
49700
49800
49900
Upvotes: 4
Reputation: 26667
You can use seq
$ seq 46600 100 49999
46600
46700
46800
46900
.
.
.
49600
49700
49800
49900
From man page
NAME
seq - print a sequence of numbers
SYNOPSIS
seq [OPTION]... LAST
seq [OPTION]... FIRST LAST
seq [OPTION]... FIRST INCREMENT LAST
Upvotes: 6
Reputation: 785376
You can use BASH's arithmetic evaluator ((...))
for this:
for ((i=46600; i<=49999; i+=100)); do echo $i; done
46500
46600
46700
...
...
49900
You can even use variable:
s=46600
e=49999
for ((i=$s; i<=$e; i+=100)); do echo $i; done
Upvotes: 3