Re: [dev] ii: how to process out in a pipeline and still page with less

From: Alexandre Niveau <alexandre.niveau_AT_gmail.com>
Date: Fri, 27 May 2022 22:39:45 +0200

Hello,

Le ven. 27 mai 2022 à 20:45, Greg Reagle <list_AT_speedpost.net> a écrit :
>
> I have a file named "out" (from ii) that I want to view. Of course, it can grow while I am viewing it. I can view it with "tail -f out" or "less +F out", both of which work. I also want to apply some processing in a pipeline, something like "tail -f out | tr a A | less" but that does not work. The less command ignores my keystrokes (unless I hit Ctrl-C, but that kills tail and tr). The "tr a A" command is arbitrary; you can substitute whatever processing you want, even just cat.
>
> This command "tail -f out | tr a A" is functional and has no bugs, but it doesn't let me use the power of less, which I crave.
>
> This command "tail out | tr a A | less" is functional and has no bugs, but it doesn't let me see newly appended lines.
>
> Can I use the power of the Unix pipeline to do text processing and the power of less for excellent paging and still be able to see new lines as they are appended? Why doesn't or can't less continue to monitor stdin from the pipeline and respond to my keystrokes from the tty?
>
> I am using Debian 11 in case it matters, with fish. But I am happy to try other shells. In fact I already have and that doesn't seem to help. I have also tried more, most, nano -, and vi -, instead of less, to no avail.
>

The simplest solution to avoid the side effect of killing tail and tr
when using ^C to quit "follow mode" in less is to redirect the output
of tr to another file, and use less +F to open that file. Like so:
tail -f out | tr a A >out2 & less +F out2

Some other solutions: https://unix.stackexchange.com/a/659175

Best,

AN
Received on Fri May 27 2022 - 22:39:45 CEST

This archive was generated by hypermail 2.3.0 : Fri May 27 2022 - 23:12:08 CEST