nl
nl linux command cheatsheet by Thamizhiniyan C S
Introduction
The nl command is used to number lines of files.
Syntax
nl [OPTION]... [FILE]...
Important Flags
Flags | Description |
---|---|
| Used for numbering body lines |
| Line number increment at each line |
| Insert line numbers according to FORMAT |
| Change first line number of the given input |
| Group of NUMBER empty lines are counted as one |
| Add any STRING after every logical line number |
| Use different NUMBER columns for line numbers |
Default Options
-b t -d ':' -f n -h n -i 1 -l 1 -n 'rn' -s -v 1 -w 6
STYLE to be used with Options
Values | Description |
---|---|
| Number all lines |
| Number only nonempty lines |
| Number no lines |
| Number only lines that contain a match for the basic regular expression, BRE |
FORMAT to be used with Options
Flags | Description |
---|---|
| Left justified, no leading zeros |
| Right justified, no leading zeros |
| Right justified, leading zeros |
Examples
Command | Description |
---|---|
To display a file with line numbers (Numbers all non-empty lines) | |
To number all lines (including empty lines also) | |
Count multiple, consecutive, non-empty lines as one | |
Override default increment | |
To make the starting line number different | |
Add a string literal after line numbers | |
Change column for line numbers | |
To number all logical lines that match the specified REGEX (number those lines that begin with F) | |
To print the lines using left-justified, no leading zeros number format | |
To print the lines using right-justified, no leading zeros number format | |
To print the lines using right-justified with leading zeros format |
Last updated