denzil_cactus has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have a XML file which has the content as below
<Marks>BALANCE OF AMOUNT RECEIVED FROM H&#</Marks>
and I am trying to use a code to convert &# into blank
as per below however in this case character & should be untouched
<Marks>BALANCE OF AMOUNT RECEIVED FROM H</Marks>
Below is the code.
sed  -e 's/&#38;//'
Please help here

Replies are listed 'Best First'.
Re: Regular Expression to replace & in XML
by FreeBeerReekingMonk (Deacon) on Nov 18, 2016 at 21:42 UTC
    This would update the files (it OVERWRITES them, so be careful)

    perl -pi -e 's/&#(?!\d+;)/ /g'  myfile.xml

    This would

    1. Find something that has &# but not &#digit;
    2. replace it with a space.

      Hi there,

      thanks for the suggestion but this solution does not work with 'sed' command as I mentioned in my question.
      If the XML has the character '&#','&' etc then the XML file can not be opened and hence I am trying to use 'sed' command.

      Below are link for XML special character translation for reference
      http://xml.silmaril.ie/specials.html
      https://www.dvteclipse.com/documentation/svlinter/How_to_use_special_characters_in_XML.3F.html

      Could you please help using 'sed' command?
Re: Regular Expression to replace & in XML
by Discipulus (Canon) on Nov 18, 2016 at 15:38 UTC
    It is easy:
    #windows double quotes! perl -e "print $ARGV[0]=~s/&#//r" "<Marks>BALANCE OF AMOUNT RECEIVED F +ROM H&#</Marks>" <Marks>BALANCE OF AMOUNT RECEIVED FROM H</Marks>

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.