Bash, grep between two lines with specified string

后端 未结 8 1971
栀梦
栀梦 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:45

    The answer by PratPor above:

    cat test.txt | grep -A10 test1 | grep -B10 test2
    

    is cool.. but if you don't know the file length:

    cat test.txt | grep -A1000 test1 | grep -B1000 test2
    

    Not deterministic, but not too bad. Anyone have better (more deterministic)?

提交回复
热议问题