Question

I would like to use gnu less -N to show line numbers on a text file, but I would like the starting number to be one different than the first line. Is it possible to change the starting line with which gnu less counts the lines yest still show the full file?

For examples:

less myfile.txt
_ asfasdfsa
_ asdfadsf
1 asdfsadfasd
2 asdfasdfsadfsad
3 adfasdfsaf
4 asdfasfdsa
5 adfadsfa

wc -l myfile.txt
7
Était-ce utile?

La solution

it would be a trivial task for awk.

awk '{s=NR<3?"-":++i;print s,$0}' file

in the above example, the line number was added from the 3rd line (the 3 in awk code)

e.g.

kent$  seq 7|awk '{s=NR<3?"-":++i;print s,$0}'
- 1
- 2
1 3
2 4
3 5
4 6
5 7

you can of course pipe the output to less to gain less features. it looks like:

awk '{s=NR<3?"-":++i;print s,$0}' file|less
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top