From nobody Mon Sep 04 06:53:58 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 4RfK9r5YVRz4rmPj for ; Mon, 4 Sep 2023 06:54:08 +0000 (UTC) (envelope-from listac@nebelschwaden.de) Received: from mail.worldserver.net (mail.worldserver.net [217.13.200.36]) (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-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "*.worldserver.net", Issuer "EuropeanSSL Server CA 2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RfK9p0l3bz3SQV for ; Mon, 4 Sep 2023 06:54:05 +0000 (UTC) (envelope-from listac@nebelschwaden.de) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=nebelschwaden.de header.s=1687803001 header.b=JlmfKQhU; spf=pass (mx1.freebsd.org: domain of listac@nebelschwaden.de designates 217.13.200.36 as permitted sender) smtp.mailfrom=listac@nebelschwaden.de; dmarc=none Received: from postpony.nebelschwaden.de (v22018114346177759.hotsrv.de [194.55.14.20]) (Authenticated sender: sendmail@nebelschwaden.de) by mail.worldserver.net (Postfix) with ESMTPSA id 251441E0FAF for ; Mon, 4 Sep 2023 08:53:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nebelschwaden.de; s=1687803001; t=1693810439; bh=h5/4Dw3ExQ/atP6MHH3nfy5uxXCUADcKywlnWZ42H58=; h=Date:Reply-To:Subject:To:References:From:In-Reply-To:From; b=JlmfKQhUUyywe6VAJEFu7Lef/s8d2iFeh8Eaww2Lo4u1IMyKvX3cJugmvd5Qj12F5 Pjka1FIxHb88TDfDNnrloMm4lOaq9o9MYbbSen70c0Bahx3LbAsPBvG8S0sO3oL6J9 ybhqhUv3AaYshp91DwyNlHOlJRSDYEiODaM7WtB2avblalsVO3/Wa7plZMo/mJ8CWe drcDGZcC3rG67JPzR1f70RO5CWoBkMB4zRY/soo56GEBg26AWczpr1hf2+yDCgN0xt ARL83dwuA9gw/aAyDq51GGJjXKsmOEpj7B+gfyZjSySZH9nrdmSTiTCCUEolBzvwYl pvOjN3IIXUJHg== Received: from [172.16.37.5] (kaperfahrt.nebelschwaden.de [172.16.37.5]) by postpony.nebelschwaden.de (Postfix) with ESMTP id 5C8CD112643 for ; Mon, 4 Sep 2023 08:53:58 +0200 (CEST) Message-ID: Date: Mon, 4 Sep 2023 08:53:58 +0200 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 User-Agent: Mozilla Thunderbird Reply-To: listac@nebelschwaden.de Subject: Re: cut off last lines of a document To: questions@freebsd.org References: <57be5495-97f8-4f22-9ae2-cd9712596e64@nebelschwaden.de> Content-Language: en-US From: Ede Wolf In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spamd-Bar: --- X-Spamd-Result: default: False [-3.59 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-0.999]; R_SPF_ALLOW(-0.20)[+ip4:217.13.200.0/24]; R_DKIM_ALLOW(-0.20)[nebelschwaden.de:s=1687803001]; RCVD_IN_DNSWL_LOW(-0.10)[217.13.200.36:from]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; PREVIOUSLY_DELIVERED(0.00)[questions@freebsd.org]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DMARC_NA(0.00)[nebelschwaden.de]; HAS_REPLYTO(0.00)[listac@nebelschwaden.de]; MID_RHS_MATCH_FROM(0.00)[]; ASN(0.00)[asn:15657, ipnet:217.13.192.0/20, country:DE]; TO_DN_NONE(0.00)[]; REPLYTO_ADDR_EQ_FROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MLMMJ_DEST(0.00)[questions@freebsd.org]; DKIM_TRACE(0.00)[nebelschwaden.de:+]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-Rspamd-Queue-Id: 4RfK9p0l3bz3SQV Am 03.09.23 um 23:16 schrieb paul beard: > This seems to meet the requirements of displaying a file minus the last > three lines. It seems portable as well: most unix-ish systems should > have these utilities. I tried to avoid any regexes…as the saying goes, > adding a regex means now you have *two* problems. At least for me it > seems to go that way. > > export COUNT=`wc -l /var/log/messages | tr -d -c '\n[:digit:]'` # get > the number of lines in the file: if needed/the filename has digits use > 'cut -f1 -d "/" to isolate > export WANT=`echo "$COUNT-3" | bc ` # subtract 3 (or however many) > head -$WANT /var/log/messages # display the remainder. > > might seem inefficient but when a raspberry π is clocked in GHz, who cares? 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. May just be my lack of shell, of course. Think rather: cat | head .. instead of head Where cat in this case is just a symbolic placeholder for any other command before the pipe. So I need to process from stdin, not from a file. Should have made this more clear, I suppose. The awk and sed solutions provided here work fine.