nl
Text processing
Usage
nl [file]Numbers lines as it prints them; by default it skips blank lines, which is why its numbers disagree with an editor until you pass -b a.
Common flags
| Flag | Meaning |
|---|---|
| -b a | Number every line; -b t, the default, skips the blank ones |
| -w | How wide the number field is |
| -s | What goes between the number and the line |
| -v | The first number to use |
| -i | How much to add per line |
Examples
nl -ba script.shNumbers every line, blank ones included.
nl -w1 -s': ' notes.txtCompact numbering with a colon.
These were built to be piped together. Three joined commands are usually shorter than one that does everything.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does nl do?
Numbers lines as it prints them; by default it skips blank lines, which is why its numbers disagree with an editor until you pass -b a.
Q. How do I type it?
nl [file] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
5 are listed here; the full set is in man nl. This command sits under Text processing.
Related commands
man page: man nl