Thursday, February 8, 2007
Command in discussion - seq
seq is a very useful command to generate sequence of numbers. Some of its uses are discussed below.
(Printing from 1 to 5)
$ seq 5
1
2
3
4
5
(Printing from 2 to 5)
$ seq 2 5
2
3
4
5
(Printing from 2 to 12, with 3 increment,FIRST INCREMENT LAST)
$ seq 2 3 12
2
5
8
11
(-s, --separator)
$ seq -s : 1 5
1:2:3:4:5
(Adding 1 to 10)
$ seq -s " + " 1 10
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10
$ expr `seq -s " + " 1 10`
55
(-w, --equal-width)
$ seq -s : -w 1 10
01:02:03:04:05:06:07:08:09:10
(Use with for loop)
$ for i in `seq 5`
> do
> echo "square of $i is `expr $i \* $i`"
> done
square of 1 is 1
square of 2 is 4
square of 3 is 9
square of 4 is 16
square of 5 is 25
which is a replacement of :
1) for i in 1 2 3 4 5
or
2) for ((i=1;i<=5;i++))
Subscribe to:
Post Comments (Atom)
© Jadu Saikia www.UNIXCL.com
No comments:
Post a Comment