4

On a regular basis, I am piping the output of some program to either head or tail.

Now, suppose that I want to see the first AND last 10 lines of piped output, such that I could do something like

 ./lotsofoutput | headtail

I am specifically looking for an easy to remember, simple and elegant solution.

Closest I got was

 ./lotsofoutput | sed -n -e '1,10p' -e 'N,$p'

Or, by means of Command to display first few and last few lines of a file

headtail is a function
headtail () 
{ 
    head -n 3 -- "$1";
    tail -n 3 -- "$1"
}
$ echo {1..10} | tr " " "\n" | headtail -
1
2
3
$
Bernhard
  • 11,992
  • 4
  • 59
  • 69

0 Answers0