From nobody Sun Sep 3 04:26:34 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 4RddyD1fkqz4sDWS for ; Sun, 3 Sep 2023 04:26:44 +0000 (UTC) (envelope-from little.analyst892@aceecat.org) Received: from beesty.loosely.org (beesty.loosely.org [IPv6:2600:3c01:e000:4c0::2]) (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 did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4RddyC2BPgz4PD3 for ; Sun, 3 Sep 2023 04:26:43 +0000 (UTC) (envelope-from little.analyst892@aceecat.org) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=aceecat.org header.s=rsa header.b=Ely8SaNG; spf=pass (mx1.freebsd.org: domain of little.analyst892@aceecat.org designates 2600:3c01:e000:4c0::2 as permitted sender) smtp.mailfrom=little.analyst892@aceecat.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=aceecat.org ; s=rsa; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:To:From:Date:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=UpwsvVkxOdmcnMGEQ7uRQUn7oBdEsHom1CugGb2Frcw=; b=Ely8SaNGqr2Woy10APHS1e527m GjPrzxUc+/CjDbS/yWDiwEOwf07cOJcYsch3SoQH2Hvtszz7HLacBTM0UWX9nsQNV6sYhqub/Fw9O 8TLy2qmGkNJMRrw7DZsaB1JLPrxK93RP1DgncJb1Ca7gIJZWrZ7b8h8Dwl12+XGD02WUC+u9HAM8R McxZ8fqSAt7vqQAWGSuFb/XXtUTirdUCKwhUDGWW+m28DwHDMvbVDdtKqFTaznIAdlzp7hTnO/dTI ILymOFB/H8vW8Ev12PUjGA8u4sSoPaBT1NINU6HHJ3p0Pgh3tms9Hce7hjq/x9m/FbQ4HfClmOzaU +gmp3+xw==; Received: from [::1] (helo=beesty ident=itz) by beesty.loosely.org with esmtp (Exim 4.96-10-042a28abf) (envelope-from ) id 1qceh0-0005kX-2y for questions@freebsd.org; Sat, 02 Sep 2023 21:26:34 -0700 Date: Sat, 2 Sep 2023 21:26:34 -0700 From: little.analyst892@aceecat.org To: questions@freebsd.org Subject: Re: cut off last lines of a document Message-ID: Mail-Followup-To: questions@freebsd.org References: <57be5495-97f8-4f22-9ae2-cd9712596e64@nebelschwaden.de> 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57be5495-97f8-4f22-9ae2-cd9712596e64@nebelschwaden.de> X-Spamd-Bar: -- X-Spamd-Result: default: False [-2.56 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-0.999]; NEURAL_HAM_SHORT(-0.66)[-0.663]; MID_RHS_NOT_FQDN(0.50)[]; R_SPF_ALLOW(-0.20)[+mx]; R_DKIM_ALLOW(-0.20)[aceecat.org:s=rsa]; ONCE_RECEIVED(0.10)[]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ONE(0.00)[1]; MLMMJ_DEST(0.00)[questions@freebsd.org]; ASN(0.00)[asn:63949, ipnet:2600:3c01::/32, country:SG]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; DKIM_TRACE(0.00)[aceecat.org:+]; BLOCKLISTDE_FAIL(0.00)[2600:3c01:e000:4c0::2:server fail]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_NO_DN(0.00)[]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; DMARC_NA(0.00)[aceecat.org]; ARC_NA(0.00)[] X-Rspamd-Queue-Id: 4RddyC2BPgz4PD3 On Fri, Sep 01, 2023 at 10:43:46AM +0200, Ede Wolf wrote: > 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? Here's my perl solution (which I have had for a while): #! /usr/bin/env perl use strict; use warnings; use Getopt::Long qw(:config require_order); use autodie; $main::char_mode = 0; @main::queue = (); $main::num_dropped = 10; sub read_one { my ($next_input) = @_; our (@queue, $num_dropped); if ($#queue + 1 >= $num_dropped) { my $next_output = shift @queue; print($next_output); } push(@queue, $next_input); } sub usage { print STDERR ("usage: notail [-c|--char_mode] [-n|--num_dropped N] [FILE ..]\n"); exit(2); } sub main { our ($char_mode, $num_dropped); GetOptions ("char_mode" => \$char_mode, "num_dropped=i" => \$num_dropped) or usage(); $/ = \1 if $char_mode; while (<>) { read_one($_); } } exit(main()); 1; __END__ -- Ian