perl - grep or sed to match a block between start and end using same pattern -


i have file following info:

start pattern1 line1 line2 ... end pattern1 line3 line4 start pattern2 ... 

my output should be:
start pattern1 line1 line2 end pattern1

if know pattern1 , can

sed '/start pattern1/,/end pattern1/p' <file> 

but here, want match pattern1 (like \s+ in perl regex) , use same (like $1) in end. how can that?

with range operator in perl, patterns aren't tested @ same time

perl -wne'print if /start ([a-za-z0-9_:]+)/ ... /end $1/' intput.txt 

updated actual pattern, specified in comments.

i tested using captures (in do block instead of print) , worked problems may lie in wait if there other captures. if don't capture in other regex works.

note use of ... instead of .., not test right operand until next evaluation.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -