Re: cut off last lines of a document
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 01 Sep 2023 15:16:59 UTC
Thanks all again for your help! I guess that awk below is the one to go for. I would have never been able to come up with those solution(s) Am 01.09.23 um 15:59 schrieb User &: > Le vendredi 01 sept. 2023 à 14:12:13 (+0200), Andreas Kusalananda Kähäri à écrit: >> Using awk: >> >> awk -v n=3 'NR > n { print buffer[NR%n] } { buffer[NR%n] = $0 }' >> >> This will print all lines except the last "n" lines. The buffer array >> is a circular buffer that contains the most recently read "n" lines. >> The code outputs nothing until the first "n" lines have been read, then >> it outputs lines from the buffer array in a circular fashion while at >> the same time filling the array with new lines from the input. > > Oh, that's beautiful. Thanks for sharing.