LinuxCommandLibrary

jot

Print sequential or random data

SYNOPSIS

jot [options] [count [begin [end [step]]]]

PARAMETERS

-a
    Pad all numbers to the same width by padding with spaces.

-b
    Specifies the begin value for the sequence (default: 1).

-c
    Interpret numbers as ASCII characters instead of numeric values.

-e
    Specifies the end value for the sequence (default: count if given, otherwise begin).

-f
    Use format string for floating-point output (e.g., "%f").

-i
    Invert the meaning of 'begin' and 'end' processing.

-n
    Do not append a newline character to the output.

-p
    Set the precision for floating-point numbers.

-r
    Generate random numbers instead of sequential numbers.

-s
    Specifies the step value for the sequence (default: 1 or -1 if begin > end).

-t
    Use string as a separator instead of newline.

-v
    Invert the test for checking if begin is greater than end.

-w
    Format the output using format, a printf-style string.

-x
    Act like xargs, reading arguments from standard input.

-z
    Do not pad numbers with leading zeros or spaces.

DESCRIPTION

jot is a versatile command-line utility used to generate sequential or random data. It can print numbers, characters, or repeated strings, making it invaluable for scripting, testing, and creating test data.

Unlike simpler tools like seq, jot offers extensive control over the output. Users can specify the count of items, the begin and end values, and the step size. It supports both integer and floating-point arithmetic. Beyond simple sequences, jot excels at generating random numbers, repeating arbitrary strings, or outputting characters based on their ASCII values. Its printf-style formatting (the -w option) allows for highly customized output.

Common applications include creating large files with predictable content, iterating through ranges in shell scripts, generating unique IDs, or supplying arguments to other commands via its xargs-like mode. Its flexibility and power make it a preferred choice for advanced shell programming tasks.

CAVEATS

When only count is specified, it defaults to the end value if begin and step are omitted, leading to potentially unexpected output if not understood.
Floating-point calculations can sometimes lead to minor precision inaccuracies.
Performance might degrade significantly when generating an extremely large number of items due to memory and output overhead.

DEFAULT ARGUMENT INTERPRETATION

The interpretation of jot arguments depends on how many numeric arguments are provided:
jot count: Outputs count numbers from 1 to count.
jot count begin: Outputs count numbers starting at begin, incrementing by 1.
jot count begin end: Outputs count numbers between begin and end (inclusive if possible), adjusting the step automatically.

PRACTICAL USE CASES

Generate 10 random numbers between 1 and 100: jot -r 10 1 100
Generate a sequence of 5 ASCII characters from 'a': jot -c 5 a
Create 3 files named 'file01.txt' to 'file03.txt': jot -w 'file%02d.txt' 3 | xargs touch

HISTORY

jot originated in 4.3BSD and is a standard utility in various BSD-derived operating systems like FreeBSD, OpenBSD, and NetBSD.
While not part of the GNU Core Utilities (which include seq), it is widely available on GNU/Linux distributions, typically provided by packages like `bsdutils`, extending the shell scripting capabilities.

SEE ALSO

seq(1), shuf(1), xargs(1), awk(1)

Copied to clipboard