[TUHS] head/sed/tail (was The Unix shell: a 50-year view)
Bakul Shah
bakul at iitbombay.org
Fri Jul 16 08:29:40 AEST 2021
On Jul 14, 2021, at 7:38 PM, Douglas McIlroy <douglas.mcilroy at dartmouth.edu> wrote:
>
> -r is weird because it enables backwards reading, but only as
> limited by count. Better would be a program, say revfile, that simply
> reads backwards by lines. Then tail p has an elegant implementation:
> revfile p | head | revfile
tail -n can be smarter in that it can simply read the last K bytes
and see if there are n lines. If not, it can read back further.
revfile would have to read the whole file, which could be a lot
more than n lines! tail -n < /dev/tty may never terminate but it
will use a small finite amount of memory.
-- Bakul
More information about the TUHS
mailing list