Date: Mon, 4 Sep 2023 08:53:58 +0200 From: Ede Wolf <listac@nebelschwaden.de> To: questions@freebsd.org Subject: Re: cut off last lines of a document Message-ID: <a9b64c1d-02a6-45c1-aaed-85e4cf622776@nebelschwaden.de> In-Reply-To: <CAMtcK2qbc1jQHXJ%2Bwu0F62o6aDQKYAx3kYARuQFZLHS6DJktRg@mail.gmail.com> References: <57be5495-97f8-4f22-9ae2-cd9712596e64@nebelschwaden.de> <uy2fdgobbejnhyctyyrbhgvhutuhtbzzxwg5wukdujyhw7h25u@74ujfxm5gjlk> <CAMtcK2qbc1jQHXJ%2Bwu0F62o6aDQKYAx3kYARuQFZLHS6DJktRg@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <file> | head .. instead of head <file> 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?a9b64c1d-02a6-45c1-aaed-85e4cf622776>