perl - multiple line tag content replacement if content matches -


i not proficient in perl, awk, or sed , have been searching web solution problem while now, wasn't successful.

i replace

<math> ... </math>

with

<math>\begin{align} ... \end{align}</math>

if ... contains \\. problem string between <math> tags can span multiple lines. managed replace tags within 1 line sed couldn't run multiple lines.

any simple solution perl, awk, or sed welcome. lot.

use separate expressions each tag , script immune multilinedness:

sed -e 's,<math>,&\\begin{align},g' -e 's,</math>,&\\end{align},g'  

edit: multiline awk version:

awk '/<math>/,/<\/math>/ {   if (index($0, "<math>")) {      a=$0   } else {     b = b $0   }   if (index($0, "</math>")) {     if (index(b,"\\\\")) {       sub("<math>","&\\begin{align}", a)       sub("</math>","\\end{align}&", b)     };      print a,b     a=""     b=""   }  }' 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -