Re: cut off last lines of a document

From: Ede Wolf <listac_at_nebelschwaden.de>
Date: Mon, 04 Sep 2023 06:53:58 UTC
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.