1. Tutorial

Write each FILE to standard output, with line numbers added.

2. Usage

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

2.1 重要常用参数

-b, —body-numbering=STYLE use STYLE for numbering body lines
-n, —number-format=FORMAT insert line numbers according to FORMAT
-w, —number-width=NUMBER use NUMBER columns for line numbers
-s, —number-separator=STRING add STRING after (possible) line number
-v, —starting-line-number=NUMBER first line number for each section
—help display this help and exit
—version output version information and exit

-f, —footer-numbering=STYLE use STYLE for numbering footer lines -h, —header-numbering=STYLE use STYLE for numbering header lines -i, —line-increment=NUMBER line number increment at each line -l, —join-blank-lines=NUMBER group of NUMBER empty lines counted as one

STYLE**:
a number all lines
t number only nonempty lines
n number no lines
pBRE number only lines that contain a match for the basic regular expression, BRE

FORMAT**:**
ln left justified, no leading zeros
rn right justified, no leading zeros
rz right justified, leading zeros

3. UseCase

  1. // abc.md
  2. # Haha
  3. ## 1. xixi
  4. ## 2. haha
  5. ## 3. wow
  6. ## 4. aef
  7. ## 5. faefao

仅对非空行增加行号,行号靠右占3起始位10,跟随 ;

  1. nl -bt -nrn -s";" -v10 -w3 abc.md
  2. 10;# Haha
  3. 11;## 1. xixi
  4. 12;## 2. haha
  5. 13;## 3. wow
  6. 14;## 4. aef
  7. 15;## 5. faefao

仅对非空行增加行号,行号靠右占2位起始97,跟随 \

  1. nl -bt -nrn -v97 -w2 -s"\\" abc.md
  2. 97\# Haha
  3. 98\## 1. xixi
  4. 99\## 2. haha
  5. 100\## 3. wow
  6. 101\## 4. aef
  7. 102\## 5. faefao