nlis a command that allows you to number the lines. Through some flags you can decide how to filter this command.
We have a file named
example.txtthat contains 5 elements, to test this command: The syntax is:
nl example.txt 1 Car 2 Computer 3 Robot 4 Smartphone 5 VideogameAs you can see, the command has numbered the lines.
- -b (regex): Specify the lines to be numbered
nl -b p^[cv] example.txt 1 Car 2 Computer 3 Videogame Robot SmartphoneThe part after the flag is used to number only the lines that start with c and v.
- -bn: The flag n goes with b, doesn't number any lines
nl -bn example.txt Car Computer Videogame Robot Smartphone
- -s: Usually nl separes the number of the line from the text with a tab, with -s
flag you can choose another separator, in this example we will use "=".
nl -s= example.txt 1=Car 2=Computer 3=Videogame 4=Robot 5=Smartphone