sed -n '/pattern1/{p; :a; N; /pattern2/!ba; s/.*
//}; p' inputfile
Explanation:
/pattern1/{ # if pattern1 is found
p # print it
:a # loop
N # and accumulate lines
/pattern2/!ba # until pattern2 is found
s/.*
// # delete the part before pattern2
}
p # print the line (it's either pattern2 or it's outside the block)
Edit:
Some versions of sed
have to be spoon-fed:
sed -n -e '/pattern1/{' -e 'p' -e ':a' -e 'N' -e '/pattern2/!ba' -e 's/.*
//' -e '}' -e 'p' inputfile
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…