in reply to extract tag form xml file

perl script needed.

One liner provided.

$ perl -F\" -ne 'print "$F[1].mml\n"' foo.xml ieqn-1.mml ieqn-2.mml ieqn-3.mml

Of course, this is tremendously fragile and does no XML parsing and therefore should never be used in production.

Replies are listed 'Best First'.
Re^2: extract tag form xml file
by marto (Cardinal) on Dec 03, 2018 at 11:26 UTC

    "Now i need this lines as separate file like below:"

    I read this as wanting the matching tag saved to individual files.

      It could certainly be interpreted that way too. Who doesn't love a gimme with a loose spec?

        Technically correct is the best kind of correct, after all

Re^2: extract tag form xml file
by Aldebaran (Curate) on Dec 04, 2018 at 02:29 UTC

    I just realized that xml is the mark-up language of the monastery. Am I replicating your result?

    $ cat 1.murugan.xml <inline-formula id="ieqn-1"><alternatives><mml:math display="inline">< +mml:mi>&#964;</mml:mi></mml:math></alternatives></inline-formula> <inline-formula id="ieqn-2"><alternatives><mml:math display="inline">< +mml:mi>&#964;</mml:mi></mml:math></alternatives></inline-formula> <inline-formula id="ieqn-3"><alternatives><mml:math display="inline">< +mml:mi>&#964;</mml:mi></mml:math></alternatives></inline-formula> $ perl -F\" -ne 'print "$F[1].mml\n"' 1.murugan.xml ieqn-1.mml .mml ieqn-2.mml .mml ieqn-3.mml $

      Indeed you are. The difference in output is due to a difference in input only. You have assumed that every other line of input is blank whereas I assumed those were just attempts by Murugan to separate the lines in markup since for some reason they (unlike you) did not enclose their data in <code> tags.

      I did say it was tremendously fragile.