How to scroll large datafile while keeping header
On terminals that support setting the scrolling region:
tailf() ( # args: <file> [<number-of-header-lines>]
trap 'tput csr 0 "$((LINES-1))"' INT
tput csr "$((1+${2-1}))" "$((LINES-1))"
tput clear
{
head -n"${2-1}"
printf "%${COLUMNS}s\n" "" | tr ' ' =
tail -n "$((LINES-1-${2-1}))" -f
} < "$1"
)
(assumes a shell like zsh
or bash
that sets the $COLUMNS
and $LINES
variables based on the size of the terminal).
If you're familiar with vim, this is probably the best option for you. You can enable horizontal-scroll-bind-only by changing 'scrollopt'
:
set scrollopt=hor
So with vim -u NONE
, you get the desired behavior with:
:set scrollopt=hor
:set nowrap
:1split
:windo set scrollbind
You may want to adjust 'sidescroll'
and 'sidescrolloff'
to change how many columns are skipped and how far from the edge skipping starts respectively.
Try this (you'll need to install multitail
):
multitail -du -t "$(head -n 1 filename)" filename
or, for headers longer than one line:
multitail -wh 2 -l "head -n 2 filename" filename
If you want to follow command output instead of a file:
multitail -wh 2 -l "command | head -n 2" -l command
or use -t
as appropriate. Note that you may need to use unbuffer
so your command output appears immediately.
You can use -D
to disable the display of status lines for the -wh
forms (it would defeat the purpose of the -t
form).