Seq: Difference between revisions
From charlesreid1
No edit summary |
|||
| Line 33: | Line 33: | ||
2 | 2 | ||
1 | 1 | ||
</source> | |||
==Decimal Numbers== | |||
Seq can handle decimal increments as well: | |||
<source> | |||
$ seq 0 0.5 5 | |||
0 | |||
0.5 | |||
1 | |||
1.5 | |||
2 | |||
2.5 | |||
3 | |||
3.5 | |||
4 | |||
4.5 | |||
5 | |||
</source> | </source> | ||
| Line 71: | Line 90: | ||
</source> | </source> | ||
==Custom Separator== | |||
Creating a comma-separated list of numbers is often more useful/interesting than each number on a separate line: | |||
<source> | |||
$ seq -s, 0 2 10 | |||
0,2,4,6,8,10, | |||
</source> | |||
You can also use escape characters, like a double-newline: | |||
<source> | |||
$ seq -s'\n\n' 0 2 10 | |||
0 | |||
2 | |||
4 | |||
6 | |||
8 | |||
10 | |||
</source> | |||
=Combining Seq with Other Unix Utilities= | =Combining Seq with Other Unix Utilities= | ||
Revision as of 20:00, 9 January 2014
The seq command can be used for creating numerical sequences of numbers.
Basic Use of Seq
If you want a list of numbers from 1 to 10:
$ seq 1 10
1
2
3
4
5
6
7
8
9
10or, if you want a backwards list:
$ seq 10 1
10
9
8
7
6
5
4
3
2
1Decimal Numbers
Seq can handle decimal increments as well:
$ seq 0 0.5 5
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5Custom Increment
If you want a sequence of numbers from A to B with a particular increment i, feed three arguments to seq: seq A i B
$ seq 0 5 50
0
5
10
15
20
25
30
35
40
45
50You can also give negative increments,
$ seq 50 -5 0
50
45
40
35
30
25
20
15
10
5
0Custom Separator
Creating a comma-separated list of numbers is often more useful/interesting than each number on a separate line:
$ seq -s, 0 2 10
0,2,4,6,8,10,You can also use escape characters, like a double-newline:
$ seq -s'\n\n' 0 2 10
0
2
4
6
8
10