number
Number lines in a file
SYNOPSIS
number [OPTION]... [FILE]...
PARAMETERS
-b STYLE, --body-numbering=STYLE
Set numbering style for body lines. STYLE can be:
a: number all lines
t: number only nonempty lines (default)
n: number nothing
pREGEXP: number only lines that contain match REGEXP regular expression
-d DELIM, --field-separator=DELIM
Use DELIM for field separator. Defaults to TAB.
-f, --first-page=NUMBER
The first page number
-h, --header=STRING
The header string
-i, --increment=NUMBER
The increment number
-n FORMAT, --number-format=FORMAT
Set number format. FORMAT can be:
ln: left aligned, no zeros
rn: right aligned, no zeros (default if -w not specified)
rz: right aligned, leading zeros (default if -w specified)
-p, --first-line-number=NUMBER
The first line number.
-s STRING, --join-string=STRING
String to append to (possible) line number. Defaults to TAB.
-v, --version
Print version information and exit.
-w WIDTH, --number-width=WIDTH
Use WIDTH columns for numbers. Default: 6
DESCRIPTION
The number command adds line numbers to the lines of a specified file or standard input. It writes the numbered output to standard output. By default, it numbers all non-blank lines, but this behavior can be modified using options to number all lines or only lines matching a specific pattern. The output format and number alignment can also be customized.
number is useful for creating easily referenced copies of text files, adding line numbers to source code for debugging, or preparing documents for printing with line number references. It is often piped with other commands to add line numbers to their output, such as cat or grep.
CAVEATS
The behavior of number can be significantly affected by locale settings, especially regarding character encoding and interpretation of whitespace. Regular expression matching can be complex, and it is important to understand the regular expression syntax used by your system.
EXAMPLES
number myfile.txt
: Numbers all non-blank lines of 'myfile.txt' and prints to standard output. number -b a myfile.txt
: Numbers all lines (including blank lines) of 'myfile.txt'.number -w 4 -n rz myfile.txt
: Numbers lines with a width of 4, right-aligned with leading zeros.
HISTORY
The number command is part of the GNU coreutils, a package of essential file, text, and shell manipulation utilities common on Unix-like operating systems. Its development has evolved alongside the GNU project, aiming to provide a free and portable alternative to proprietary Unix tools. It's primarily used for adding sequential numbers to lines of text, often in preparation for printing or documentation.