Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Sep 2023 19:02:13 -0500
From:      Tom Browder <tom.browder@gmail.com>
To:        listac@nebelschwaden.de
Cc:        User Questions <questions@freebsd.org>
Subject:   Re: cut off last lines of a document
Message-ID:  <CAFMGiz_ojoqwyKOh3zo8CUVbtvYxt0YRaO7_%2BY1uucDPSJSQMQ@mail.gmail.com>
In-Reply-To: <57be5495-97f8-4f22-9ae2-cd9712596e64@nebelschwaden.de>
References:  <57be5495-97f8-4f22-9ae2-cd9712596e64@nebelschwaden.de>

next in thread | previous in thread | raw e-mail | index | archive | help
--0000000000000581300604cdb108
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Fri, Sep 1, 2023 at 05:23 Ede Wolf <listac@nebelschwaden.de> wrote:
> Hello,
>  From a file/output with an unknown amount of lines, I would like to
> filter out, or not display, the last 3 lines. Is there a way to archive
> this?

Ede, I would like to know your use case. You have had lots of suggestions
of arcane shell scripting solutions for use on any Unix-like host, but I
want to suggest an alternative which is even more universal: use a Raku
script (see the solution below). Let me explain.

Short version
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

In any line of work, I believe you should automate any work you can to give
more time for other tasks.  For the work that can be automated by shell
scripting, Raku provides easier coding and easier maintenance.

Long version
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

In my younger days I was a semipro sysadmin for years with a DoD
contractor. I introduced Linux for our CAD developers when we were still
using SGI workstations that cost about $25K and $6K annually to support.

I introduced the old Yggdrasil Linux installed on a small IBM PC as a much
cheaper alternative as we started weaning ourselves off big iron and
providing all analysts with his or her own workstation. Over the years I
used Perl to do more complicated sysadmin support for my team of analysts
and moved away csh to bash in the process. Note Perl is now available by
default on the Linux distros I=E2=80=99m familiar with , but I have been us=
ing Raku
as its replacement since 2015 and, while not automatically available, it is
easily installable as packaged in major Linux distros as well as for
NetBSD. Other installation support is provided for Windows and MacOS. See <
rakudo.org> for details.

RAKU SOLUTION

So, with Raku installed, I view a file =E2=80=9Csomefile=E2=80=9D in a term=
inal with a Raku
one-liner like this at the shell prompt:

$ raku -e 'say $_ for "somefile".IO.lines[^(*-3)]'
...all but the last three lines scroll by...

(Note I would make the one-liner reusable by putting that line in a bash
script file with a suitable and meaningful name, something like
"cat-less-3-lines.sh."

Happy rakuing!


-Tom

--0000000000000581300604cdb108
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div><div><div><div><div><div><div>On Fri, Sep 1, 2023 at 05:23 Ede Wolf &l=
t;<a href=3D"mailto:listac@nebelschwaden.de" target=3D"_blank">listac@nebel=
schwaden.de</a>&gt; wrote:<br>
&gt; Hello,<br>
&gt;=C2=A0 From a file/output with an unknown amount of lines, I would like=
 to<br>
&gt; filter out, or not display, the last 3 lines. Is there a way to archiv=
e<br>
&gt; this?<br>
<br></div></div></div></div></div></div></div><div><div><div dir=3D"auto">E=
de, I would like to know your use case. You have had lots of suggestions of=
 arcane shell scripting solutions for use on any Unix-like host, but I want=
 to suggest an alternative which is even more universal: use a Raku script =
(see the solution below). Let me explain.<br>
<br>Short version</div><div dir=3D"auto">=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</di=
v><div dir=3D"auto"><br></div><div dir=3D"auto">In any line of work, I beli=
eve you should automate any work you can to give more time for other tasks.=
=C2=A0 For the work that can be automated by shell scripting, Raku provides=
 easier coding and easier maintenance.</div><div dir=3D"auto"><br></div><di=
v dir=3D"auto">Long version</div><div dir=3D"auto">=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D</div><div dir=3D"auto"><br>
In my younger days I was a semipro sysadmin for years with a DoD contractor=
. I introduced Linux for our CAD developers when we were still using SGI wo=
rkstations that cost about $25K and $6K annually to support.<br>
<br>
I introduced the old Yggdrasil Linux installed on a small IBM PC as a much =
cheaper alternative as we started weaning ourselves off big iron and provid=
ing all analysts with his or her own workstation. Over the years I used Per=
l to do more complicated sysadmin support for my team of analysts and moved=
 away csh to bash in the process. Note Perl is now available by default on =
the Linux distros I=E2=80=99m familiar with , but I have been using Raku as=
 its replacement since 2015 and, while not automatically available, it is e=
asily installable as packaged in major Linux distros as well as for NetBSD.=
 Other installation support is provided for Windows and MacOS. See &lt;<a h=
ref=3D"http://rakudo.org" rel=3D"noreferrer" target=3D"_blank">rakudo.org</=
a>&gt; for details.</div><div dir=3D"auto">
<br>
RAKU SOLUTION<br>
<br>
So, with Raku installed, I view a file =E2=80=9Csomefile=E2=80=9D in a term=
inal with a Raku one-liner like this at the shell prompt:<br>
<br>
$ raku -e &#39;say $_ for &quot;somefile&quot;.IO.lines[^(*-3)]&#39;</div><=
div dir=3D"auto">...all but the last three lines scroll by...<br>
<br>(Note I would make the one-liner reusable by putting that line in a bas=
h script file with a suitable and meaningful name, something like &quot;cat=
-less-3-lines.sh.&quot;</div><div dir=3D"auto">
<br>
Happy rakuing!</div></div></div><div><div><div><div><div><div><div><br>
<br>
-Tom<br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

--0000000000000581300604cdb108--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFMGiz_ojoqwyKOh3zo8CUVbtvYxt0YRaO7_%2BY1uucDPSJSQMQ>