Previous: factor invocation, Up: Numeric operations


26.2 seq: Print numeric sequences

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

     seq [option]... last
     seq [option]... first last
     seq [option]... first increment last

seq prints the numbers from first to last by increment. By default, each number is printed on a separate line. When increment is not specified, it defaults to ‘1’, even when first is larger than last. first also defaults to ‘1’. So seq 1 prints ‘1’, but seq 0 and seq 10 5 produce no output. Floating-point numbers may be specified. See Floating point.

The program accepts the following options. Also see Common options. Options must precede operands.

-f format
--format=format
Print all numbers using format. format must contain exactly one of the ‘printf’-style floating point conversion specifications ‘%a’, ‘%e’, ‘%f’, ‘%g’, ‘%A’, ‘%E’, ‘%F’, ‘%G’. The ‘%’ may be followed by zero or more flags taken from the set ‘-+#0 '’, then an optional width containing one or more digits, then an optional precision consisting of a ‘.’ followed by zero or more digits. format may also contain any number of ‘%%’ conversion specifications. All conversion specifications have the same meaning as with ‘printf’.

The default format is derived from first, step, and last. If these all use a fixed point decimal representation, the default format is ‘%.pf’, where p is the minimum precision that can represent the output numbers exactly. Otherwise, the default format is ‘%g’.

-s string
--separator=string
Separate numbers with string; default is a newline. The output always terminates with a newline.
-w
--equal-width
Print all numbers with the same width, by padding with leading zeros. first, step, and last should all use a fixed point decimal representation. (To have other kinds of padding, use --format).

You can get finer-grained control over output with -f:

     $ seq -f '(%9.2E)' -9e5 1.1e6 1.3e6
     (-9.00E+05)
     ( 2.00E+05)
     ( 1.30E+06)

If you want hexadecimal integer output, you can use printf to perform the conversion:

     $ printf '%x\n' $(seq 1048575 1024 1050623)
     fffff
     1003ff
     1007ff

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

     $ seq 1000000 | xargs printf '%x\n' | tail -n 3
     f423e
     f423f
     f4240

To generate octal output, use the printf %o format instead of %x.

On most systems, seq can produce whole-number output for values up to at least 2^53. Larger integers are approximated. The details differ depending on your floating-point implementation. See Floating point. A common case is that seq works with integers through 2^64, and larger integers may not be numerically correct:

     $ seq 18446744073709551616 1 18446744073709551618
     18446744073709551616
     18446744073709551616
     18446744073709551618

Be careful when using seq with outlandish values: otherwise you may see surprising results, as seq uses floating point internally. For example, on the x86 platform, where the internal representation uses a 64-bit fraction, the command:

     seq 1 0.0000000000000000001 1.0000000000000000009

outputs 1.0000000000000000007 twice and skips 1.0000000000000000008.

An exit status of zero indicates success, and a nonzero value indicates failure.