Linux nl command help and examples(What is, Concept and Definition)

On Unix-like operating systems, the nl command numbers the lines in a file.


This document describes the GNU/Linux version of nl .

Syntax

nl [ OPTION ]...[ FILE ]...

Options




























-b , --body numbering= STYLE use STYLE to number body lines
-d , --section-delimiter= CC use CC to separate logical pages
-f , -footer number= STYLE use STYLE to number footer lines
-h , --header-numbering= STYLE use STYLE to number header lines
-i , --line-increment= NUMBER increment of line number on each line
-l , --join-blank-lines= NUMBER group of NUMBER empty lines counted as one
-n , --number-format= FORMAT insert line numbers according to FORMAT
-p , --no-renumber do not reset line numbers on logical pages
-s , --separator-number= STRING add STRING after the (possible) line number
-v , --start line number= NUMBER first line number on each logical page
-w , --number-width= NUMBER use NUMBER columns for line numbers
--help show help and exit
--version displays version information and exits

By default, nl select -v1-i1-l1-sTAB-w6-nrn-hn-bt-fn . CC are two delimiting characters to separate logical pages.A second missing character implies a colon (: ).


For a backslash ( \ ), two backslashes ( \\ ).


STYLE is one of:










a number all the lines
t number only non-empty lines
n number without lines
p BRE number only lines containing a match for the basic regular expression, BRE

FORMAT is one of:








ln left justified, no leading zeros
rn right-justified, no leading zeros
rz right justified, zeros left

Examples

cat list.txt apples
oranges
potatoes
lemons
garlic nl list.txt 1 apples 2 oranges 3 potatoes 4 lemons 5 garlics

In the example above, we used the cat command to display the contents of list.txt .Then we use nl to number each line and display the result at the standard output.

nl list.txt> nlist.txt cat nlist.txt 1 apples 2 oranges 3 potatoes 4 lemons 5 garlics

In the example above, we run the same nl command, but redirect the output to a new file, nlist.txt .Then we use cat to display the results.

wc : displays a count of lines, words, and characters in a file.

Comments