2

This question already has an answer here:

For a file containing 20 lines, lines 6-10 can be printed using following command:

head -10 filename | tail -5

Can this exactly same thing be done without using 'head' and 'tail' commands ??

Please comment the link if similar question already exists.

marked as duplicate by Stéphane Chazelas, Ramesh, slm Aug 25 '14 at 13:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

sed would work well here

seq 20 | sed '6,10!d'
6
7
8
9
10

You could use this as well: sed -n '6,10p'

Or awk, awk '6 <= NR && NR <= 10'

  • 2
    sed '6,$!d;20q' to avoid reading the whole input. – Stéphane Chazelas Aug 25 '14 at 12:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.