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

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


head -2 myownfile | tail -1 

should do what you want


head -2 displays first 2 lines of a file

$ head -2 myownfile.txtfoohello world

tail -1 displays last line of a file:

$ head -2 myownfile.txt | tail -1hello world


I'm a bit late to the party here, but a more flexible way of doing this would be to use awk rather than using head and tail.

Your command would look like this:

awk 'NR==2' myfile.txt

hello world