in reply to Strip out value between xml tags

I'm trying to strip out the value that is between <CorpActnEvtId>12345678</CorpActnEvtId>.

By which, I think you mean you want to retrieve the value between the CorpActnEvtid opening and closing tags... (Strip out, to me, usually menas you want to delete it, and leave the rest.)

Parsing it with one of the XML modules is the right answer.

A quick answer, if this is a one-off thing or something, is to use something like

$junk =~ /<CorpActnEvtId>(\d+)<\/CorpActnEvtId>/; my $id = $1;

I might do it that way if I had a pile of data I had to munge up just once, and if I didn't need much more from that snippet of XML. But even so, it's making some assumptions (like the ID is always just digits and there is no whitespace within the tag.) This is terribly brittle and, if you have to do it once, you'll probably have to do it again. So I'm not recommending you do it this way, particularly as you weren't able to work it out on your own.

That said, here's some rope; it's up to you not to hang yourself with it.

"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re^2: Strip out value between xml tags
by dirtdog (Monk) on Mar 24, 2015 at 14:33 UTC

    Thanks! I ended up using the following sed command:

    grep CorpActnEvtId | sed -e 's/.*<CorpActnEvtId>//' | sed -e 's/<\/Cor +pActnEvtId.*//' > file.out

    I apologize for the late response. Something urgently came up that day and i'm just now able to reply.