1

Given the following ...

$ less -N file.txt
      1 first line
      2 second line
      3 third line
      4 fourth line
file.txt (END)

... I'd like to do something like this:

$ less -N --STARTING-NUMBER=0 file.txt
      0 first line
      1 second line
      2 third line
      3 fourth line
file.txt (END)

In other words, I'd like to be able to specify which value the line numbering starts from.

Note that this is possible using nl:

$ nl -v 0 file.txt
     0  first line
     1  second line
     2  third line
     3  fourth line

But -N in less can be toggled on and off without leaving less, whereas if I pipe the above into less, the line numbers could not be toggled off.

If less has something like nl's -v option - or there were any other way to achieve the same - that would be awesome. But I don't see it in the less(1) man pages.

  • I feel like https://unix.stackexchange.com would be a more appropriate home for this question, albeit weakly as to that specific destination. – Tommy Dec 28 '22 at 01:07

1 Answers1

0

Here comes a quick patch

--- line.c.bak  2022-12-07 22:30:28
+++ line.c  2022-12-28 01:40:08
@@ -367,7 +367,7 @@
            len = 0;
        else
        {
-           linenumtoa(linenum, buf);
+           linenumtoa(linenum - 1, buf);
            len = (int) strlen(buf);
        }
        for (i = 0; i < linenum_width - len; i++)

or you make a feature request at https://github.com/gwsw/less/issues.

Polluks
  • 525
  • 2
  • 8
  • 19