Reputation: 2517
What unix shell command can I use to get lines x (e.g. 10) to y (e.g. to 15) from a file. grep
doesn't seem to help and except doing a for loop I can't think of anything else.
Upvotes: 17
Views: 19079
Reputation: 67301
awk:
awk 'NR>=10 and NR<=15' your_file
perl:
perl -lne 'print if($.>=10 && $.<=15)' your_file
tested below:
> cat temp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
> nawk 'NR>=10&&NR<=15' temp
10
11
12
13
14
15
> perl -lne 'print if($.>=10&&$.<=15)' temp
10
11
12
13
14
15
>
Upvotes: 5
Reputation: 121407
You can use sed
:
sed -n '5,10p' filename
to print lines from 5 to 10.
Upvotes: 39