?

Log in

No account? Create an account

Previous Entry | Next Entry

Command: seq - print a sequence of numbers

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++))
  

Profile

jaduks
Jadu Kumar Saikia

Latest Month

January 2008
S M T W T F S
  12345
6789101112
13141516171819
20212223242526
2728293031  
Powered by LiveJournal.com
Designed by chasethestars