Less command introduction:
As you know Unix less command writes the contents of a file onto the screen a page at a time and this is one of the utilities using which one can view the content of a file without opening it in an editor.
Press the [space-bar] if you want to see another page, and type [q] if you want to quit reading.
This is how we can print line number with Unix less command.
From man page of CAT(1):
number all output lines
$ cat -n file.txt | less
will print the line number in-front of each line.
From man page of LESS(1):
-N or --LINE-NUMBERS
Causes a line number to be displayed at the beginning of each line in the display.
$ less -N file.txt
will do the same as 1) above.
3) One can set the following to print line number with less by default:
$ export LESS='-RS#3NM~g'
- Numbering lines in a file using Bash awk
- Open file at required line number in Unix vi editor