Bash method for viewing beginning and end of file

bashtext processing

On queue-based clusters the Queue of pending jobs is shown from a command, say showqueue.

The command returns, in columns, a list of reasonable data like names, etc, but the columns/data don't really matter for the question.

I like using the utility watch like watch showqueue at times (with an alias of alias watch="watch " to force alias expansion of my command to watch). There is valuable data (Running jobs), in the first few lines, then pending jobs, etc, and some valuable summaries at the end.

However, at times the output of showqueue goes off the screen (Unbelievable, I know)! Ideally, I'd like some way to be able to see the beginning and end of the file at the same time.

The best I have so far is: showqueue > file; head -n 20 file > file2; echo "..." >> file2 ; tail -n 20 file >> file2; cat file2, and using watch on an alias of that.

Does anyone know of anything a little more flexible or single-utility? My solution gets a little nastier with bash loops to make the "…" break multilined, it's not adaptive to resizing the terminal window at all, and I'm sure there's more that I missed.

Any suggestions?

Best Answer

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

$ showqueue | (head && tail)
Related Question