perl -pi -e '/(<level(1|2))(\sid=\".*\")*>/;$&?$2==1?$b=$3:$_=~s;($1); +$1$b;g:1' input
In reply to Re^4: Regex problem while parsing tagged, hierarchical data
by Mago
in thread Regex problem while parsing tagged, hierarchical data
by sivaramanm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |