From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24054 invoked from network); 16 Jul 2021 12:10:56 -0000 Received: from minnie.tuhs.org (45.79.103.53) by inbox.vuxu.org with ESMTPUTF8; 16 Jul 2021 12:10:56 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id 303659C83D; Fri, 16 Jul 2021 22:10:53 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id CBD339C7F1; Fri, 16 Jul 2021 22:10:20 +1000 (AEST) Authentication-Results: minnie.tuhs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=dartmouth.edu header.i=@dartmouth.edu header.b="LwOHVuLI"; dkim-atps=neutral Received: by minnie.tuhs.org (Postfix, from userid 112) id DEEA49C7F1; Fri, 16 Jul 2021 22:10:18 +1000 (AEST) Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by minnie.tuhs.org (Postfix) with ESMTPS id 206A29C7F0 for ; Fri, 16 Jul 2021 22:10:18 +1000 (AEST) Received: by mail-wr1-f50.google.com with SMTP id v5so11863609wrt.3 for ; Fri, 16 Jul 2021 05:10:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dartmouth.edu; s=google1; h=mime-version:from:date:message-id:subject:to; bh=lMUXl2Tb9M8rTcWzlwibWk8TMioxu6X6Dm++rc8o+oE=; b=LwOHVuLIyWgqm9JnHd66nwWEZa4c6tc/PRA+wgFI/zUrRYc8g7QRMKOyygYKwecMTB 9NsgpRNgSt2miJcknyKyOsv7rKsuv6X1n2G0GlxCalbhaGJtkqO8MJlB3nItPtU/TrSF yOVCiyBgszwIS7NEKuIRuikYkL6mk4H7HRECXhWHzMdgbNCLscfEURHsKr6aa4BSa9U9 gDjFNmLPLc+UiB43wu4p0sqhdbFW6pRL+tNMOMRokp6jI7lnrngJoKaW8IsyLbmeGBHu pg3txJ2zXCRzg5HPEDYUO3qlCIfSlwsFTbf/3QcgXQJ+X4JUb9xNRdmZZaAa1xLHndCH BpIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=lMUXl2Tb9M8rTcWzlwibWk8TMioxu6X6Dm++rc8o+oE=; b=VA6xcLlzb9yCfy7psPEMvnJwQCWzX1m+xc5uXrUBwX0csR2s2OJs9hIcoC0RBi2lzx PbkKhGVIsFgZBo4uAJ+wuvhnHV44boiQe124ttqpi6d+pC7+hCrj3SlouRgXhKB71/YF T0GjrfmqhCHll5NEAI8ZePWdvsOwlJp3cYeuzADjbhx6KuUG1a6YbTex5RktkQIcpfqA YRiSMB+KI/xYbtjUhh2Wr0M8mr6kLkKWvF/OC8EFizdWd+ViE4qNTGL+cKLkiAJEYID4 I7/FtlZRQUWRgELW8P0sGV4zMmO2VMXahQFfHPqVjhHsih6xdT6GlmQGod//CMMAtp6O 57tg== X-Gm-Message-State: AOAM531XRly6G6HVrkqPuF+0GZSit1JLvheDnyM9SDxaBpIBnbS/FBWz C3PxnrvcJl7vvgD3gh8s9FXGRrq6NcaAgx9jhi1ofaXFoOtzCg== X-Google-Smtp-Source: ABdhPJxYvVBxRSUSvQyNwAYMmd4+ljlnMmi3sYTrRD5lbpTMltLB6H2VTtX1VWVsDgDr10O3asFXv6pqfZZax+rP4cg= X-Received: by 2002:a5d:6d86:: with SMTP id l6mr11957407wrs.260.1626437416186; Fri, 16 Jul 2021 05:10:16 -0700 (PDT) MIME-Version: 1.0 From: Douglas McIlroy Date: Fri, 16 Jul 2021 08:09:59 -0400 Message-ID: To: The Eunuchs Hysterical Society Content-Type: text/plain; charset="UTF-8" Subject: Re: [TUHS] head/sed/tail (was The Unix shell: a 50-year view) X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" >> -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. Revfile would work the same way. When head has seen enough and terminates, revfile will get SIGPIPE and stop. I agree that, depending on scheduling and buffer management, revfile might read more than tail -n, but it wouldn't read the whole of a humongous file. Doug