From nobody Mon Sep 4 15:35:37 2023 X-Original-To: questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RfXlh6BwPz4sKDW for ; Mon, 4 Sep 2023 15:35:44 +0000 (UTC) (envelope-from ralf-mardorf@riseup.net) Received: from mx0.riseup.net (mx0.riseup.net [198.252.153.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mx0.riseup.net", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RfXlg4Whpz3VvS for ; Mon, 4 Sep 2023 15:35:43 +0000 (UTC) (envelope-from ralf-mardorf@riseup.net) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=riseup.net header.s=squak header.b=GfpFbX6V; spf=pass (mx1.freebsd.org: domain of ralf-mardorf@riseup.net designates 198.252.153.6 as permitted sender) smtp.mailfrom=ralf-mardorf@riseup.net; dmarc=pass (policy=none) header.from=riseup.net Received: from fews02-sea.riseup.net (fews02-sea-pn.riseup.net [10.0.1.112]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx0.riseup.net (Postfix) with ESMTPS id 4RfXld3KQVz9t83 for ; Mon, 4 Sep 2023 15:35:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1693841741; bh=3j0t6+mw9kdS0bUAX9L4LVePr0UOfcsU3TGhn/PZO6s=; h=Subject:From:To:Date:In-Reply-To:References:From; b=GfpFbX6VWH+VSFw/uizMa8d/AJjUGMfHMkopprU0lsCLuba231Sh/MFk1gtYJGC23 mkXcxM2kCCcxuX9FeRlXDK/haruJHZ2tXYhB1e3PkwEfMvV8Lw1cymQrvvumRmDiD7 dDfjC3sLGsHMXWByvoyFwD1tp7yMN3Mi3D7Zrj4M= X-Riseup-User-ID: 53AFC58B533AC5EE486CACD12D3BA0505258D1D7D13BC643CA50E9C1E473B16C Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews02-sea.riseup.net (Postfix) with ESMTPSA id 4RfXlc5W9WzFpfK for ; Mon, 4 Sep 2023 15:35:40 +0000 (UTC) Message-ID: <9195f2126712560684ab72fea6f434b791afc333.camel@riseup.net> Subject: Re: cut off last lines of a document From: Ralf Mardorf To: questions@freebsd.org Date: Mon, 04 Sep 2023 17:35:37 +0200 In-Reply-To: <86edjet336.fsf@ltc.des.no> References: <57be5495-97f8-4f22-9ae2-cd9712596e64@nebelschwaden.de> <86edjet336.fsf@ltc.des.no> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.06 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.96)[-0.957]; DMARC_POLICY_ALLOW(-0.50)[riseup.net,none]; R_DKIM_ALLOW(-0.20)[riseup.net:s=squak]; R_SPF_ALLOW(-0.20)[+a:mx0.riseup.net]; MIME_GOOD(-0.10)[text/plain]; RCVD_IN_DNSWL_LOW(-0.10)[198.252.153.6:from]; DWL_DNSWL_NONE(0.00)[riseup.net:dkim]; FROM_EQ_ENVFROM(0.00)[]; MLMMJ_DEST(0.00)[questions@freebsd.org]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; ASN(0.00)[asn:16652, ipnet:198.252.153.0/24, country:US]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; DKIM_TRACE(0.00)[riseup.net:+]; PREVIOUSLY_DELIVERED(0.00)[questions@freebsd.org]; TO_DN_NONE(0.00)[]; BLOCKLISTDE_FAIL(0.00)[198.252.153.6:server fail]; RCPT_COUNT_ONE(0.00)[1]; FROM_HAS_DN(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 4RfXlg4Whpz3VvS On Mon, 2023-09-04 at 16:39 +0200, Dag-Erling Sm=C3=B8rgrav wrote: > Pipe-friendly pure shell solution: >=20 > drop_last_three() { > local a b c d > read a > read b > read c > while read d ; do > echo "$a" > a=3D"$b" > b=3D"$c" > c=3D"$d" > done > } Hi, this way it takes quite a while to get the last 3 lines of the Encyclop=C3=A6dia Britannica ;). Let alone that I don't understand how to u= se your shell function without rewriting it. =E2=80=A2 rocketmouse@archlinux ~/Desktop=20 $ cat read3 #!/bin/bash =20 drop_last_three() { local a b c d read a read b read c while read d ; do a=3D"$b" b=3D"$c" c=3D"$d" done echo "$a" echo "$b" echo "$c" } =20 drop_last_three < 2.txt =E2=80=A2 rocketmouse@archlinux ~/Desktop=20 $ cat 2.txt=20 1 2 3 4 5 6 7 8 9 10 =E2=80=A2 rocketmouse@archlinux ~/Desktop=20 $ time tail -3 2.txt=20 8 9 10 =20 real 0m0.010s user 0m0.002s sys 0m0.008s =E2=80=A2 rocketmouse@archlinux ~/Desktop=20 $ time ./read3=20 8 9 10 =20 real 0m0.017s user 0m0.008s sys 0m0.010s =20 The above test was done on a desktop PC. On an iPad Pro I'm using https://ish.app/ . This "app" is Alpine Linux which is build around busybox. It doesn't matter what shell I'm using (not necessarily busybox), iSH is always very slow. Such a workaround IMO isn't a good idea. I still recommend to let a script test what OS is used and to use different commands depending on the OS. Regards, Ralf