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=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 7229 invoked from network); 16 Jul 2021 14:32:28 -0000 Received: from minnie.tuhs.org (45.79.103.53) by inbox.vuxu.org with ESMTPUTF8; 16 Jul 2021 14:32:28 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id 3D2389C84D; Sat, 17 Jul 2021 00:32:25 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id 5C05F9C7F1; Sat, 17 Jul 2021 00:32:09 +1000 (AEST) Authentication-Results: minnie.tuhs.org; dkim=pass (2048-bit key; unprotected) header.d=iitbombay-org.20150623.gappssmtp.com header.i=@iitbombay-org.20150623.gappssmtp.com header.b="1ocCoCI+"; dkim-atps=neutral Received: by minnie.tuhs.org (Postfix, from userid 112) id 28ECD9C7F1; Sat, 17 Jul 2021 00:32:08 +1000 (AEST) Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) by minnie.tuhs.org (Postfix) with ESMTPS id 763009C7F0 for ; Sat, 17 Jul 2021 00:32:07 +1000 (AEST) Received: by mail-oo1-f49.google.com with SMTP id a17-20020a4ad5d10000b0290263c143bcb2so1044734oot.7 for ; Fri, 16 Jul 2021 07:32:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iitbombay-org.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=o83tLHiQwtyZ2Nr5q3W8Nv4rfOjB3o61qHrXOQPaN9E=; b=1ocCoCI+3GkWFbumwEkAa3sZNEKzQE0nWqfS6wtFIHZszVDYJ9Sa1yL5BmVV3Zt/7F YpEqDipMPZ9QIpagbTAJ9pDdddu8FvgZFvWh3TPr445Pp+GczGicY3YlAHRH2Ne+u/Ak Bc6Lin2Is09y+1FAuSRAbSqvs/5CRfj82F0WQMVMegX260L13XJK0TXmaODYXX5BCzIS GNbpNK0AUWOHqcEi/litAr4iJo4aSdEnXjzqIvZO/DlpQbcaDVxX11eIE+x8N77gUDy7 PzlxbZYZOCBdgoynoQLZGx+aTRSauashXyLBY8vPE5G+p131Clh7MR4WZJdsabBiz2XG RuGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=o83tLHiQwtyZ2Nr5q3W8Nv4rfOjB3o61qHrXOQPaN9E=; b=rswCBBgc9ODwekqiDeqieweDzRVQLEGzbspAnHqbwzDYP5CYYO08G4bfP+D3WyxODm Q1n1sbVzwywN6I8XbgupPmLIVG2BO5mk2A4fn+YixS2P32sMVkQA/FEQXZKt6X1ypNV+ REslTeY5loJ0AR2x14lfEYwAPNlXq0VLGuIhrqT0nrTu3A12bZb7l+l7ORDzzq79H5KG p3HkgBmqSYe+/DVCDVXRBCltsYLTtUT3+r8D2dn7QGbfQZj52vrH/w0lXAGgenlVqygC afj4e+4cThZIIDxJe6cPVGwOC+CexwIf6pyT0L5lgR7EH+kt1o/f6CQO3lawGvKKan/M EzvQ== X-Gm-Message-State: AOAM533HY98uHaAlA/tFkK+wLqybBzcBWc3XLdW9cybDCry7gvdCyMSn k9BWOdsRCCB5fO42/bVFQoDvJw== X-Google-Smtp-Source: ABdhPJzkDWB8Sgjdmv6jXY7rGJiWRz4BBQlT+M0PZGajtQhgzOhg2eh2ay3MpidtZwknMwAA+CVNwQ== X-Received: by 2002:a4a:cf07:: with SMTP id l7mr684780oos.11.1626445926739; Fri, 16 Jul 2021 07:32:06 -0700 (PDT) Received: from smtpclient.apple (107-215-223-229.lightspeed.sntcca.sbcglobal.net. [107.215.223.229]) by smtp.gmail.com with ESMTPSA id w190sm2092348oif.17.2021.07.16.07.32.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jul 2021 07:32:06 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.100.0.2.22\)) From: Bakul Shah In-Reply-To: Date: Fri, 16 Jul 2021 07:32:05 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Douglas McIlroy X-Mailer: Apple Mail (2.3654.100.0.2.22) 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: , Cc: The Eunuchs Hysterical Society Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" On Jul 16, 2021, at 5:09 AM, Douglas McIlroy = wrote: >=20 >>> -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 >=20 >> 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. >=20 > 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. Good point! But when the input is from a device it would have to buffer up everything since it doesn't know how much head would want. No big deal of course but I was just pointing out that tail can "behave better" in all cases! -- Bakul