How to print text between two line numbers into a

2019-05-24 03:37发布

问题:

I have a file like this (numbers on first column is line number)

30.<unit id=20>
31....
32.</unit>
33.<unit id=40?
34....
35.</unit>
36<unit id=20>
37...
38.</unit>
39.<unit id=40?
40....
41</unit>

I want to print lines between two line numbers, say 32 and 39. How can I accomplish this in Unix?
I'm new to unix. Note: I don't want perl scripts please.

回答1:

use sed

sed -n '/^32/,/^39/p' file


回答2:

Another way with sed:

 sed -n '32,39p' filename


回答3:

sed -n '32,39p' input > output

Note that this ignores your line numbering and simply prints lines 32 through 39. If you want to match the strings, use something like Fredrik's proposed solution.



回答4:

I guess you should try this

sed '32,39!d' input > output


标签: shell unix sed awk