To get specified lines from file

Hi,

I have a file which contains 100 lines. Now i need to get lines from 45-50 only. For this i used head and tail command . But i want to get this using single command instead of two commands(head and tail)

-> is it possble to get with single command ? if so How ?

Thanks in advance.

Try

sed -n '45,50p' filename

Try this:

awk 'NR==45, NR==50' inputfile
awk 'NR>=45 && NR<=50' inputfile

Or,

awk 'NR>=45&&NR<=50{print}' inputfile
awk 'NR>=45{print}NR==51{exit}' file

Assuming that you have the
file in an array already, then;

${ARRAY[@]:45:5}

will extract the arrays starting at 45
with a length of 5.

1 Like