Sometimes I use the -N option for less to add linenumbers. However when I redirect the output of less the linenumers are no longer displayed. A simple demonstration is to try the following two commands: less -N /etc/nsswitch.conf less -N /etc/nsswitch.conf | less Wichert.
[Please preserve the CC to nnn-forwarded@bugs when replying] That's the report:
Thomas Schoepf wrote: This is intentional behavior. When the output of less is not a tty (i.e. a pipe or a file), the input is simply sent unchanged to the output, as if less were "cat". This is so you could, for example, redirect to a different pager: man sh | more In this case, if less did its normal processing (interpreting backspaces, etc), the more program (or whatever is on the other end of the pipe) might get confused. It's arguable that -N processing could legitimately be done prior to sending to a pipe or file, but the way it is currently designed, no processing of any kind is done unless the output is a tty. --Mark
Previously Mark Nudelman wrote: I would argue that since I explicitly request less to do some processing of the data (adding linenumbers in this case) it should always be done. For the other processing you mention (like control-character transformation) no explicit request is made, so it should indeed not be done when the output is not a tty. Wichert.
Hi, the attached patch let's less output linenumbers when requested and output is not a tty. It works on my i386 Linux system (even with DOS .txt files) but I can't test it on other architectures. I hope this helps you. Thomas
Hello Mark, I've attached a patch for the bug with Ref number 212: less -N with redirected output doesn't produce line numbers. It's using the same number formatting as is used when the output is a tty. Hope this helps you. Thomas