GNU Info

Info Node: ( invocation

( invocation

Prev: factor invocation Up: Numeric operations
Enter node , (file) or (file)node

`seq': Print numeric sequences

   `seq' prints a sequence of numbers to standard output.  Synopses:

     seq [OPTION]... [FIRST [INCREMENT]] LAST...

   `seq' prints the numbers from FIRST to LAST by INCREMENT.  By
default, FIRST and INCREMENT are both 1, and each number is printed on
its own line.  All numbers can be reals, not just integers.

   The program accepts the following options.  Also see Note: Common

     Print all numbers using FORMAT; default `%g'.  FORMAT must contain
     exactly one of the floating point output formats `%e', `%f', or

     Separate numbers with STRING; default is a newline.  The output
     always terminates with a newline.

     Print all numbers with the same width, by padding with leading
     zeroes.  (To have other kinds of padding, use `--format').

   If you want to use `seq' to print sequences of large integer values,
don't use the default `%g' format since it can result in loss of

     $ seq 1000000 1000001

   Instead, you can use the format, `%1.f', to print large decimal
numbers with no exponent and no decimal point.

     $ seq --format=%1.f 1000000 1000001

   If you want hexadecimal output, you can use `printf' to perform the

     $ printf %x'\n' `seq -f %1.f 1048575 1024 1050623`

   For very long lists of numbers, use xargs to avoid system
limitations on the length of an argument list:

     $ seq -f %1.f 1000000 | xargs printf %x'\n' |tail -3

   To generate octal output, use the printf `%o' format instead of
`%x'.  Note however that using printf works only for numbers smaller
than `2^32':

     $ printf "%x\n" `seq -f %1.f 4294967295 4294967296`
     bash: printf: 4294967296: Numerical result out of range

   On most systems, seq can produce whole-number output for values up to
`2^53', so here's a more general approach to base conversion that also
happens to be more robust for such large numbers.  It works by using
`bc' and setting its output radix variable, OBASE, to `16' in this case
to produce hexadecimal output.

     $ (echo obase=16; seq -f %1.f 4294967295 4294967296)|bc

   Be careful when using `seq' with a fractional INCREMENT, otherwise
you may see surprising results.  Most people would expect to see `0.3'
printed as the last number in this example:

     $ seq -s' ' 0 .1 .3
     0 0.1 0.2

   But doesn't happen on most systems because `seq' is implemented using
binary floating point arithmetic (via the C `double' type) - which
means some decimal numbers like `.1' cannot be represented exactly.
That in turn means some nonintuitive conditions like `.1 * 3 > .3' will
end up being true.

   To work around that in the above example, use a slightly larger
number as the LAST value:

     $ seq -s' ' 0 .1 .31
     0 0.1 0.2 0.3

   In general, when using an INCREMENT with a fractional part, where
(LAST - FIRST) / INCREMENT is (mathematically) a whole number, specify
a slightly larger (or smaller, if INCREMENT is negative) value for LAST
to ensure that LAST is the final value printed by seq.

automatically generated by info2www version