Using combination of "head" and "tail" to display middle line of the file in Unix

Ali picture Ali · Nov 1, 2011 · Viewed 53.6k times · Source

If I have a file name myownfile.txt which contains 3 lines of text.

foo
hello world
bar

I want to display the line in the middle which is hello world by using head and tail command only.

Answer

ennuikiller picture ennuikiller · Nov 1, 2011
head -2 myownfile | tail -1 

should do what you want