Bash method for viewing beginning and end of file

Are you looking to do something like the following? Shows output from both head and tail.

$ showqueue | (head && tail)

Using the same approach as you, using a temporary file, but doing it slightly shorter:

showqueue >/tmp/q.out; head -n 20 /tmp/q.out; echo '...'; tail -n 20 /tmp/q.out

This would not suffer from the same issues as discussed under another answer, but would possibly show the same lines twice if the output was shorter than 40 lines.


awk solution for an arbitrary number of lines shown from the head and the tail (change n=3 to set the amount):

$ seq 99999 | awk -v n=3 'NR <= n; NR > n { a[NR] = $0; delete a[NR-n]; } 
     END { print "..."; for (i = NR-n+1; i <= NR; i++) if (i in a) print a[i]; }'
1
2
3
...
99997
99998
99999

As it's written, the head and tail parts will not overlap, even if the input is shorter than 2*n lines.

In some awk implementations, using for (x in a) print a[x]; in the END part also works. But in general, it's not guaranteed to return the array entries in the correct order, and doesn't in e.g. mawk.