unix - head AND tail of file

toop picture toop · Dec 24, 2011 · Viewed 63.8k times · Source

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 1-10 and 190-200 in one go.

Answer

Aleksandra Zalcman picture Aleksandra Zalcman · Dec 24, 2011

You can simply:

(head; tail) < file.txt

And if you need to uses pipes for some reason then like this:

cat file.txt | (head; tail)

Note: will print duplicated lines if number of lines in file.txt is smaller than default lines of head + default lines of tail.