On a windows box (no CYGWIN etc) using sed how can you “delete all but the last n lines” from a text file ?
On *nix you could get tail/cat/wc involved to pre-process the input file but how can you do this using pure sed ?
[FWIW the sed is the GNU sed; the platform is Windows 2003].
From this list of sed one-liners:
On Windows:
That example is for n = 10. Replace 11 with n + 1. It basically works by keeping a running list in the pattern space. For the first 10 lines, it just appends to the pattern space (N), then loops to the beginning. For 11 and later, it also deletes the first line of the pattern space. Finally, at the ($), it quits, which automatically prints the final n lines.
This is really not sed’s strong suit, though. I would just install coreutils from gnuwin32.