I wanted to tail the last 100 lines of a file to the same file, but the commandtail -n 100 file > file doesn't work, I assume because the stdout gets written to the file 'live', before everything was read from the original file.Is there some way to pipe the output to something, that then keeps it until all 100 lines are there, and then outputs it to the file? Or just another way to shorten the file in this way?
Command line 'buffer'
bash;files;stdout
sponge from moreutils is good for this. It will:soak up standard input and write to a fileYou use it like this:tail -n 100 file | sponge fileto get exactly the effect you want.