#30264 less: less forgets formatting when output is redirected

Package:
less
Source:
less
Description:
pager program similar to more
Submitter:
Wichert Akkerman
Date:
2025-03-31 13:15:02 UTC
Severity:
normal
Tags:
#30264#5
Date:
1998-12-02 01:29:57 UTC
From:
To:
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.

#30264#8
Date:
1999-09-09 21:16:51 UTC
From:
To:
[Please preserve the CC to nnn-forwarded@bugs when replying]

That's the report:

#30264#9
Date:
1999-09-09 23:01:26 UTC
From:
To:
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

#30264#10
Date:
1999-09-10 02:17:41 UTC
From:
To:
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.

#30264#15
Date:
2000-01-31 23:19:51 UTC
From:
To:
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

#30264#24
Date:
2002-09-01 11:24:03 UTC
From:
To:
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