nl command on Linux (number lines)
The nl command in Linux (number lines) is used to number the lines of a file. The command considers special conditions for the file header and footer.
The commonly used options are:
- -h sub-option: Used to format the text header. The default is not to number the header;
- -b sub-option: Used to format the body of the text. The default is to number only non-empty lines;
- -f sub-option: Used to format the text footer. The default is to not number the footer.
The sub-options are:
- A: Number all lines;
- t: Number only completed lines;
- n: Do not number lines.
Example:
Assume that the arquivo.txt has the following content:
And we use the nl command:
The result will be:
———————————————————————————————————
1 Carlos Torres 8.5 80% Approved
2 José Antônio 10.0 100% Approved
3 Maria de Lourdes 10.0 100% Approved
4 Mário Cabral 9.5 100% Approved —
———————————————————————————————————————————————————————————————————————————————————————— Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.
Did you like it?
Share