简体   繁体   中英

Using SED to Search and Replace Text in an XML file

I am using the SSED command line tool in Windows to perform a global search and replace on text in an XML file (this XML file is actually an export of a Task Manager Task). When I look at the file before modifying it shows fine in notepad as text. However after the search and replace is complete when I view the file many characters have been changed to unreadable text (special characters).

Anyone experienced this and know a way to ensure it remains as a text file?

Doing this editing with a sed(1) script is going to be fragile and may break easily if the output or formatting of the XML changes.

Instead, look into xmlstarlet http://xmlstar.sourceforge.net/ for a similar tool that works with XML files. It's likely already in your distro, but might not be installed yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM