in reply to Re^4: Regex problem while parsing tagged, hierarchical data
in thread Regex problem while parsing tagged, hierarchical data

perl -pi -e '/(<level(1|2))( id=\".*\")*>/;$&?$2==1?$b=$3:$_=~s;($1);$1$b;g:1' input

Replies are listed 'Best First'.
Re^6: Regex problem while parsing tagged, hierarchical data
by mk. (Friar) on Sep 19, 2006 at 13:57 UTC
    perl -pi -e '/1 id="(.*)"/?$ci=$1:s/2>/2 id="$ci">/g' input
    (:


    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    "one who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever."

    mk at perl dot org dot br
      33 chars !
      perl -pi -e '/l1(\sid=.*)>/?$a=$1:s;l2>;l2$a>;' input


      Mago
      mago@rio.pm.org