Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Silently replacing characters in XML file using sed - can you help? 2

Status
Not open for further replies.

bazil2

Technical User
Feb 15, 2010
148
DE
(Elementary user)

I have a programme that is generating XML files.

Sometimes the XML file contains forbidden or undesirable characters in its values; for example:

...
<Name>Mr & Mrs Smith</Name>
...
<GermanStreet>Straße</GermanStreet>


I am looking for a method to change for example the ampersand and German character to specific alternatives:

& = and
ß = ss

Can anyone please help me with the correct syntax for using sed (or alternative) to do this?

In layman's terms, I want to 'scan' all lines in any XML files that lands in a specific input directory and there swap out the charcters accordingly; I read about he binary sed.

Best regards
 
Depending on how many of replacements you need to make, a series of tr (translate/transliterate) commands in a bash script would do that.


Bash:
tr "from_string" "to_string" < path-to-file.ext

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
In [tt]sed[/tt]...

Code:
cat oldfile.xml | sed 's/&/and/g;s/ß/ss/g' > newfile.xml
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top