nl
文本处理
用法
nl [file]一边输出一边给行编号;默认跳过空行,所以编号和编辑器不一致,加上 -b a 才对得上。
常用选项
| 选项 | 含义 |
|---|---|
| -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 |
示例
nl -ba script.shNumbers every line, blank ones included.
nl -w1 -s': ' notes.txtCompact numbering with a colon.
它们本来就是用管道串起来用的。串三条往往比让一条命令做完所有事更短。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. nl 是做什么的?
一边输出一边给行编号;默认跳过空行,所以编号和编辑器不一致,加上 -b a 才对得上。
Q. 怎么写?
nl [file] —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 5 个,完整列表在 man nl。这条命令属于文本处理。
相关命令
man 手册: man nl