Say you have a txt file, what is the command to view the top 10 lines and bottom 10 lines of file simultaneously?
i.e. if the file is 200 lines long, then view lines
It took make a lot of time to end-up with this solution which, seems to be the only one that covered all use cases (so far):
command | tee full.log | stdbuf -i0 -o0 -e0 awk -v offset=${MAX_LINES:-200} \
'{
if (NR <= offset) print;
else {
a[NR] = $0;
delete a[NR-offset];
printf "." > "/dev/stderr"
}
}
END {
print "" > "/dev/stderr";
for(i=NR-offset+1 > offset ? NR-offset+1: offset+1 ;i<=NR;i++)
{ print a[i]}
}'
Feature list: