Print the middle line of any file UNIX -



Print the middle line of any file UNIX -

i have print middle line of text file without sed nor awk.

for example, next file.txt:

line 1 line 2 line 3 line 4 line 5

i need like:

$ command -flags file.txt line 3

is there command?

thanks.

not efficient, works in bash.

use wc -l count lines, , split two. utilize tail -n +n | head -n 1 print nth line (where n starts @ 1).

$ cat input.txt b c d e $ tail -n +$(((`cat input.txt | wc -l` / 2) + 1)) input.txt | head -n 1 c

note file number of lines has no single "middle line".

i cat-ed file wc -l wouldn't print filename.

file unix text printing line

Comments

Popular posts from this blog

Php operator `break` doesn't stop while -

ubuntu - Bash Script to Check That Files Are Being Created -

vim: Search & replace -