Use “tail -f” to monitor and report, but the top line should be always fixed on the screen.

Title: Use �tail -f� to monitor and report, but the top line should be always fixed on the screen.
Hi, dear Unix experts,

I am trying to find a Unix command (or scripting) on how to continuously display a text file of its last several lines of contents. But during this displaying, I want some of the top lines are always displayed on the screen top when the scrolling contents reach the screen top.

To make a simple, a text file �test001.log� is in its running process with the ending lines adding.

tab1	tab2	tab3	tab4	tab5
0.9	5.0	17.7	9.7	19.9
0.6	9.1	4.3	0.6	41.9
0.0	2.8	14.9	5.0	5.6
0.2	5.8	62.4	17.3	41.5
0.6	8.0	74.9	0.7	19.4
0.7	4.3	48.1	2.8	30.3
0.0	5.3	0.3	16.4	42.8
0.2	7.8	70.8	11.6	10.8
0.6	7.5	89.4	19.7	34.9
0.4	2.5	88.5	0.1	22.7
0.4	1.1	41.3	8.4	18.6

Say, I want to use some commands like �tail �f�, but it will show a total number of 10 lines. The top line (possibly several lines in the middle) always shows �tab1 tab2 tab3 tab4 tab5�. The rest 9 lines show the last latest updated 9 lines. Such scrolling should not exceed outside my Unix screen shell.

I�ve tried to search such function in many websites, but haven�t found useful information. I would think this function is very useful. But can I do it?:stuck_out_tongue:

Thanks in advance.

#!/bin/ksh

while :
do
  clear
  printf "tab1\ttab2\ttab3\ttab4"
  tail -9 test001.log
  sleep 5
done

man console_codes:

e.g. echo -en "\033[2;45r" followed by an ^L (ctrl L, clear screen) will clear the screen, put your first line (=header) into row 1, and then scroll happily the text coming below that, i.e. between lines 2 and 45.