nl
Linux Commands - Managing Files and Text

nl

The nl command is used to number lines in a text file. The command allows you to add options to create the style of numbering required. Here is an example:



nl -b t data

1 acpi

2 adduser.conf

3 adjtime

4 aliases

5 aliases.db

6 alsa

7 alternatives

8 anacrontab

9 apm

---cut---


In this example the style to number only lines that have text has been chosen.

Options

-b set numbering to style chosen, t is the default

-f set the footer number style n being the default

-h set the header numbering n being the default


Numbering Styles

A set a number for every line even if empty

t number only lines with text

n do not number lines

p textstring search for a specific text string in the file

Here is an example of searching for a text string which is searching for the text string vim.


nl -b pvim data

1 vim

vnc.conf

w3m

wgetrc

X11

xdg

xml

xpdf