Date: Mon, 04 Sep 2023 17:35:37 +0200 From: Ralf Mardorf <ralf-mardorf@riseup.net> To: questions@freebsd.org Subject: Re: cut off last lines of a document Message-ID: <9195f2126712560684ab72fea6f434b791afc333.camel@riseup.net> In-Reply-To: <86edjet336.fsf@ltc.des.no> References: <57be5495-97f8-4f22-9ae2-cd9712596e64@nebelschwaden.de> <uy2fdgobbejnhyctyyrbhgvhutuhtbzzxwg5wukdujyhw7h25u@74ujfxm5gjlk> <CAMtcK2qbc1jQHXJ%2Bwu0F62o6aDQKYAx3kYARuQFZLHS6DJktRg@mail.gmail.com> <a9b64c1d-02a6-45c1-aaed-85e4cf622776@nebelschwaden.de> <86edjet336.fsf@ltc.des.no>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9195f2126712560684ab72fea6f434b791afc333.camel>