Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Sep 2023 11:46:58 -0400
From:      Paul Procacci <pprocacci@gmail.com>
To:        listac@nebelschwaden.de
Cc:        questions@freebsd.org
Subject:   Re: cut off last lines of a document
Message-ID:  <CAFbbPujBWGDKGD7gJrgmMB-DmqG_1jYbAbZ_FV4w5QiAzafR9A@mail.gmail.com>
In-Reply-To: <de480aeb-3f8c-4be2-8162-6d9f033f201a@nebelschwaden.de>
References:  <57be5495-97f8-4f22-9ae2-cd9712596e64@nebelschwaden.de> <de480aeb-3f8c-4be2-8162-6d9f033f201a@nebelschwaden.de>

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

On Fri, Sep 1, 2023 at 6:53=E2=80=AFAM Ede Wolf <listac@nebelschwaden.de> w=
rote:

> Am 01.09.23 um 10:43 schrieb Ede Wolf:
> > 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?
> >
> > For those also using linux, there is a "head -n -3" for this. That
> > negative number option is not available on FreeBSD, but maybe there is
> > an alterative way of doing this? Preferably /bin/sh compatible.
> >
> > Thanks
> >
> > Ede
> >
>
> As a sidenote: If possible, I would like to avoid using "tail -r | tail
> -n +4 | tail -r" as well, as it again is specific to FreeBSD, so if
> there is a more universal solution, that would be preferred. Even though
> this of course is a FreeBSD mailing list.
>
>
>
With these restrictions, you could use something like:

sed -e :a -e '$d;N;2,3ba' -e 'P;D' <filename>

~Paul
--=20
__________________

:(){ :|:& };:

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

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">=
<div dir=3D"ltr" class=3D"gmail_attr">On Fri, Sep 1, 2023 at 6:53=E2=80=AFA=
M Ede Wolf &lt;<a href=3D"mailto:listac@nebelschwaden.de">listac@nebelschwa=
den.de</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"m=
argin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left=
:1ex">Am 01.09.23 um 10:43 schrieb Ede Wolf:<br>
&gt; Hello,<br>
&gt; <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>
&gt; <br>
&gt; For those also using linux, there is a &quot;head -n -3&quot; for this=
. That <br>
&gt; negative number option is not available on FreeBSD, but maybe there is=
 <br>
&gt; an alterative way of doing this? Preferably /bin/sh compatible.<br>
&gt; <br>
&gt; Thanks<br>
&gt; <br>
&gt; Ede<br>
&gt; <br>
<br>
As a sidenote: If possible, I would like to avoid using &quot;tail -r | tai=
l <br>
-n +4 | tail -r&quot; as well, as it again is specific to FreeBSD, so if <b=
r>
there is a more universal solution, that would be preferred. Even though <b=
r>
this of course is a FreeBSD mailing list.<br>
<br>
<br>
</blockquote></div><br clear=3D"all">
With these restrictions, you could use something like:<br><br>sed -e :a -e =
&#39;$d;N;2,3ba&#39; -e &#39;P;D&#39; &lt;filename&gt;

<br><div><br></div><div>~Paul<br></div><span class=3D"gmail_signature_prefi=
x">-- </span><br><div dir=3D"ltr" class=3D"gmail_signature">_______________=
___<br><br>:(){ :|:&amp; };:</div></div>

--000000000000e8fc9606044e1294--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFbbPujBWGDKGD7gJrgmMB-DmqG_1jYbAbZ_FV4w5QiAzafR9A>