Algo parecido com isto:
sed '/Hymn/,/Amen/{ # in this range
/Hymn/{ # if line matches Hymn
s/.*/\small\{\uppercase\{&\}\}\normalsize/ # replace as required
h # copy over the hold space
s/.*/\begin\{verse\}/ # replace with \begin{verse}
H # append to hold space
d # delete the line
}
/Amen/!{ # if line doesn't match Amen
/^$/!{ # and if line is not empty
s/$/\\/ # add trailing \
}
H # append to hold space
d # then delete line
}
//{ # if line matches Amen
s/$/\\!/ # add trailing \!
H # append to hold space
s/.*/\end\{verse\}/ # replace with \end{verse}
H # append to hold space
s/.*// # empty pattern space
x # exchange buffers
s/\n\n/!&/g # add ! at end of each para
}
}
' infile
ou, se você preferir um gnu sed
two-liner:
sed '/Hymn/,/Amen/{/Hymn/{s/.*/\small\{\uppercase\{\&\}\}\normalsize/;h;s/.*/\begin\{verse\}/;H;d}
/Amen/!{/^$/!{s/$/\\/};H;d};//{s/$/\\!/;H;s/.*/\end\{verse\}/;H;s/.*//;x;s/\n\n/!&/g}}' infile
Envie com sua amostra:
\small{\uppercase{Hymn I}}\normalsize
\begin{verse}
Conditor alme siderum,\
Aeterna lux credentium,\
Christe, redemptor omnium,\
Exaudi preces supplicum.\!
Qui condolens interitu\
Mortis perire saeculum,\
Salvasti mundum languidum,\
Donans reis remedium.\!
Vergente mundi vespere,\
Uti sponsus de thalamo,\
Egressus honestissima\
Virginis matris clausula. Amen.\!
\end{verse}
\small{\uppercase{Hymn II}}\normalsize
\begin{verse}
...\
... Amen.\!
\end{verse}