What I'd like to do is to run a command, write all output to a file and display the first n lines.
in this example n=10
One solution I don't really like is:
./program > tempfile ; cat tempfile >> thefile ; head -n 10 tempfile
What I tried is
./program | tee -a thefile | head -n 10
However here the problem is, that ./program is terminated prematurely
Is there any trick without creating an intermediate temp file. (like a head command just displaying the first n lines, but continuing to read the rest silently)
One way to reproduce the issue with the pipeline and head is:
n=0 ; while [[ $n -lt 200 ]] ; do echo ======================== $n ; n=$((n + 1)) ; done | tee -a toto | head -n 3 ; echo "-" ; tail -n 200 toto
In fact for me the last line of file
toto is random and varies but is almost never line 199.