nlx
Number lines of files.
Mirrors GNU nl. Run it as nlx, or as gnux nlx.
Synopsis
nlx [OPTION]... [FILE]...GNU reference
Description
nlx writes each FILE to standard output with line numbers added. With no FILE, or when FILE is -, it reads standard input; several FILEs are numbered as one stream. By default non-empty lines are numbered from 1, right-aligned in a 6-column field followed by a tab, and empty lines get the same width of blanks so the text stays aligned. -b STYLE chooses which lines are numbered: a (all), t (non-empty, the default), n (none) or pBRE (those matching the POSIX basic regular expression BRE). -n FORMAT is ln (left-aligned), rn (right-aligned) or rz (zero-padded); -w sets the width, -s the separator, -v the first number and -i the increment (both may be zero or negative). -l N with -b a numbers only every Nth of a run of empty lines. Input may be split into logical pages of header, body and footer sections by lines holding only ':::', '::' or ':' (change the two characters with -d; an empty -d turns sections off); each delimiter prints as an empty line, -h and -f choose the numbering of headers and footers (none by default), and numbering restarts at every header unless -p. Every output line ends with a newline, a last line without one included.
Permissions
Needs read permission on each FILE and search permission on the directories leading to it. Nothing is ever modified.
Use cases
- Quoting a snippet of code or a config file with line numbers in a review or a bug report.
- Numbering the entries of a list, such as a playlist or a set of steps.
- Finding the line numbers of matching lines with
-bp. - Producing zero-padded numbers for fixed-width records with
-nrz. - Numbering paginated documents section by section with the : delimiters.
Flags
-b, --body-numbering STYLE use STYLE for numbering body lines (a, t, n or pBRE; default t)
-f, --footer-numbering STYLE use STYLE for numbering footer lines (default n)
-h, --header-numbering STYLE use STYLE for numbering header lines (default n)
--help display this help and exit
-l, --join-blank-lines NUMBER group of NUMBER empty lines counted as one (default 1)
-i, --line-increment string line number increment at each line (default 1)
-p, --no-renumber do not reset line numbers for each section
-n, --number-format FORMAT insert line numbers according to FORMAT (ln, rn or rz; default rn)
-s, --number-separator STRING add STRING after (possible) line number (default TAB)
-w, --number-width NUMBER use NUMBER columns for line numbers (default 6)
-d, --section-delimiter CC use CC for logical page delimiters (default \:)
-v, --starting-line-number string first line number for each section (default 1)
--version output version information and exitExamples
Quote a config file with line numbers in a bug report
nlx nginx.conf | headx -n 5 1 user www-data;
2 worker_processes auto;
3 events {
4 worker_connections 768;Number every line, empty ones included, to match an editor's line numbers
nlx -b a main.goFind which lines of a crontab are active jobs (not comments)
nlx -b 'p^[^#]' crontab.txtTurn a list of steps into a numbered checklist
nlx -w 2 -s '. ' steps.txt 1. Back up the database
2. Stop the service
3. Run the migrationGive records fixed-width, zero-padded IDs
nlx -n rz -w 5 -s , names.txt > names.csv00001,Ada
00002,Grace
00003,LinusContinue numbering where yesterday's log left off
nlx -v 1043 today.logNumber in steps of 10, leaving room to insert lines later
nlx -i 10 -v 10 program.basNumber a git diff's lines to discuss them in a review
git diff | nlx -b aNumber lines left-aligned with no padding before the text
nlx -n ln -w 1 -s ' ' todo.txtNumber two chapters as one continuous document
nlx chapter1.txt chapter2.txt > book.txtCollapse runs of empty lines so only every second one gets a number
nlx -b a -l 2 poem.txtNumber lines in the portable gnux shell
gnux shell -c 'sortx names.txt | uniqx | nlx -w 3'Options
Each option has a page of its own, with its usage and examples.
- -b, --body-numbering: Use STYLE for numbering body lines (a, t, n or pBRE; default t).
- -f, --footer-numbering: Use STYLE for numbering footer lines (default n).
- -h, --header-numbering: Use STYLE for numbering header lines (default n).
- -l, --join-blank-lines: Group of NUMBER empty lines counted as one (default 1).
- -i, --line-increment: Line number increment at each line (default 1).
- -p, --no-renumber: Do not reset line numbers for each section.
- -n, --number-format: Insert line numbers according to FORMAT (
ln, rn or rz; default rn). - -s, --number-separator: Add STRING after (possible) line number (default TAB).
- -w, --number-width: Use NUMBER columns for line numbers (default 6).
- -d, --section-delimiter: Use CC for logical page delimiters (default :).
- -v, --starting-line-number: First line number for each section (default 1).
Exit status
| Status | Meaning |
|---|---|
| 0 | success: every operand was processed |
| 1 | failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake |
Help in the terminal
nlx --help # options, first examples, exit status
gnux help nlx # this page: the full manual
gnux help nlx --OPTION # one option in depth, with its examples