seq : To generate a sequence of numbers

seq can be used to generate a sequence of numbers separated by any kind of separator as required.

$ seq 10 1 2 3 4 5 6 7 8 9 10

By default seq generates the range of numbers starting from 1. We can generate the list from any starting number by mentioning the stating number also as an argument.

$ seq 5 10 5 6 7 8 9 10

By default the numbers are generated separated by new lines. We can change the separator by using the option -s

$ seq -s “:” 5 10 5:6:7:8:9:10

We can make the number to be of equal length using the option -w

$ seq -w -s “:” 5 10 05:06:07:08:09:10

The increment by default is by one number,this can be changed by passing the increment number as the second argument.

$ seq -w -s “:” 5 2 20 05:07:09:11:13:15:17:19

The number 2 as the second argument indicates that the increment is to be by two numbers.

We can also generate a reverse seq of numbers

$ seq -w -s “:” 10 -1 5 10:09:08:07:06:05


Tags: ,
Copyright 2017. All rights reserved.

Posted November 1, 2012 by Tux Think in category "Linux