Date: Mon, 04 Sep 2023 16:39:25 +0200 From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@FreeBSD.org> To: Ede Wolf <listac@nebelschwaden.de> Cc: questions@freebsd.org Subject: Re: cut off last lines of a document Message-ID: <86edjet336.fsf@ltc.des.no> In-Reply-To: <a9b64c1d-02a6-45c1-aaed-85e4cf622776@nebelschwaden.de> (Ede Wolf's message of "Mon, 4 Sep 2023 08:53:58 %2B0200") References: <57be5495-97f8-4f22-9ae2-cd9712596e64@nebelschwaden.de> <uy2fdgobbejnhyctyyrbhgvhutuhtbzzxwg5wukdujyhw7h25u@74ujfxm5gjlk> <CAMtcK2qbc1jQHXJ%2Bwu0F62o6aDQKYAx3kYARuQFZLHS6DJktRg@mail.gmail.com> <a9b64c1d-02a6-45c1-aaed-85e4cf622776@nebelschwaden.de>
next in thread | previous in thread | raw e-mail | index | archive | help
Ede Wolf <listac@nebelschwaden.de> writes: > Am 03.09.23 um 23:16 schrieb paul beard: > > export COUNT=3D`wc -l /var/log/messages | tr -d -c '\n[:digit:]'` # > > export WANT=3D`echo "$COUNT-3" | bc ` # subtract 3 (or however many) > > head -$WANT /var/log/messages # display the remainder. 1) there is no need to export the variables 2) don't use backticks, use $() instead 3) if you use 'wc -l <foo' instead of 'wc -l foo' you don't need tr 3b) alternatively, use read: wc -l foo | read COUNT FILENAME 4) the shell can do the math for you: 'head -$((COUNT-3)) foo' > Thanks, but the problem I currently see here, as with the suggestion > of Archimedes earlier, I am currently not easily able to convert this > into a feed from stdin. Pipe-friendly pure shell solution: 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 } DES --=20 Dag-Erling Sm=C3=B8rgrav - des@FreeBSD.org
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86edjet336.fsf>