LinuxCommandLibrary

seq

Print sequences of numbers

TLDR

Print a sequence from 1 to 10

$ seq 10
copy

Print a sequence from 10 to 20
$ seq 10 20
copy

Print every 3rd number from 5 to 20
$ seq 5 3 20
copy

Separate the output with a space instead of a newline
$ seq [[-s|--separator]] " " [5 3 20]
copy

Format output width to a minimum of 4 digits padding with zeros as necessary
$ seq [[-f|--format]] "%04g" [5 3 20]
copy

Print all numbers with the same width
$ seq [[-w|--equal-width]] [5 3 20]
copy

SYNOPSIS

seq [options] [FIRST [INCREMENT]] LAST

PARAMETERS

-f FORMAT
    Use printf style FORMAT

-s STRING
    Use STRING as separator (default: newline)

-w, --equal-width
    Pad with leading zeros for equal width

DESCRIPTION

seq prints a sequence of numbers from FIRST to LAST in steps of INCREMENT. It's commonly used in shell scripts for generating numbered sequences, loop iterations, and creating test data.

CAVEATS

Floating-point sequences may have precision issues. Not available on all systems (use shell arithmetic as alternative).

EXAMPLES

seq 5 - Print 1 to 5
seq 2 10 - Print 2 to 10
seq 0 2 10 - Print 0,2,4,6,8,10
seq -w 01 10 - Print 01 to 10
seq -s, 5 - Print 1,2,3,4,5

SEE ALSO

jot(1), yes(1), printf(1)

Copied to clipboard