seq
General
You can iterate the sequence of numbers in bash
by two ways. One is by using seq
command and another is by specifying range in for loop
Table of Content
Commands
Commands | Description |
---|---|
seq [Start] [Stop] | standard sequence with [Start] as start point (start point is optional, if not set it 1 will be assumed) and [Stop] as stop point |
seq [Start] [Step] [Stop] | by adding the [Step] you can specify the sice of the setps, also negative steps are possible |
seq -w [Stop] | equalize width by padding with leading zeroes |
seq -s [Seperator] [Stop] | uses [Seperator] instead of newline |
seq -f [Format] [Stop] | sets the formarting and use printf style floating-point FORMAT |
Samples
Standard sequence
$ seq 5
1
2
3
4
5
$ seq 10 15
11
12
13
14
15
Sequence with steps
$ seq 10 2 15
10
12
14
$ seq 15 -2 10
15
13
11
Equalize with padding zeroes
$ seq -w 10
01
02
03
04
05
06
07
08
09
10
$ seq -w 010
001
002
003
004
005
006
007
008
009
010
Sequence with seperators
$ seq -s " - " 10 15
10 - 11 - 12 - 13 - 14 - 15
Formarting sequence output
$ seq -f "Kohle Kohle Kohle, Kohle, Kohle (%g)" 10 15
Kohle Kohle Kohle, Kohle, Kohle (10)
Kohle Kohle Kohle, Kohle, Kohle (11)
Kohle Kohle Kohle, Kohle, Kohle (12)
Kohle Kohle Kohle, Kohle, Kohle (13)
Kohle Kohle Kohle, Kohle, Kohle (14)
Kohle Kohle Kohle, Kohle, Kohle (15)
$ seq -f "Bananaaaaaaaaaaa v%f" 3 0.3 6
Bananaaaaaaaaaaa v3.000000
Bananaaaaaaaaaaa v3.300000
Bananaaaaaaaaaaa v3.600000
Bananaaaaaaaaaaa v3.900000
Bananaaaaaaaaaaa v4.200000
Bananaaaaaaaaaaa v4.500000
Bananaaaaaaaaaaa v4.800000
Bananaaaaaaaaaaa v5.100000
Bananaaaaaaaaaaa v5.400000
Bananaaaaaaaaaaa v5.700000
Bananaaaaaaaaaaa v6.000000