Reputation: 135
I have example file:
<i>text</i>
verse 19 3 1 text2
verse 19 3 2 text3
<i>text4</i>
verse 19 4 1 text5
verse 19 4 1 text6
verse 19 4 1 text7
And I need to convert it to:
pericope 19 3 1 <i>text</i>
verse 19 3 1 text2
verse 19 3 2 text3
pericope 19 4 1 <i>text4</i>
verse 19 4 1 text5
verse 19 4 1 text6
verse 19 4 1 text7
How to build regex for this?
Upvotes: 0
Views: 50
Reputation: 11
Assuming you're doing this in vim and taking the numbers from the first line after the text tag then this regex works:
:%s/\(<i>text\d\?<\/i>\n\)\(verse\(\(\s\+\d\+\)\{3}\)\)/periscope\3 \1\2
Upvotes: 0
Reputation: 784998
You can use awk
:
awk '/<i>/{p=$0;next} p{s=$0; sub(/ +[^ ]+$/, "", s); print "pericope", s, p; p=""} 1' file
pericope verse 19 3 1 <i>text</i>
verse 19 3 1 text2
verse 19 3 2 text3
pericope verse 19 4 1 <i>text4</i>
verse 19 4 1 text5
verse 19 4 1 text6
verse 19 4 1 text7
p
when you get a line with <i>
"pericope", s, p
p
to ""
1
Upvotes: 1