Bash, grep between two lines with specified string

后端 未结 8 1961
栀梦
栀梦 2020-11-27 12:59

Example:

a43
test1
abc
cvb
bnm
test2
kfo

I need all lines between test1 and test2. Normal grep does not work in this case. Do you have any

8条回答
  •  抹茶落季
    2020-11-27 13:34

    You could use sed:

    sed -n '/test1/,/test2/p' filename
    

    In order to exclude the lines containing test1 and test2, say:

    sed -n '/test1/,/test2/{/test1/b;/test2/b;p}' filename
    

提交回复
热议问题