使用SED搜索和替换XML文件中的文本

时间:2021-01-07 19:32:28

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).

我在Windows中使用SSED命令行工具执行全局搜索并替换XML文件中的文本(此XML文件实际上是任务管理器任务的导出)。当我在修改之前查看文件时,它在文本中显示在记事本中。但是,当我查看文件时,搜索和替换完成后,许多字符已更改为不可读的文本(特殊字符)。

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

任何人都经历过这种情况并知道如何确保它仍然是文本文件?

1 个解决方案

#1


0  

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.

使用sed(1)脚本进行编辑将变得很脆弱,如果XML的输出或格式发生变化,可能会很容易破坏。

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.

相反,请查看xmlstarlet http://xmlstar.sourceforge.net/以获取与XML文件一起使用的类似工具。它可能已经在您的发行版中,但可能尚未安装。

#1


0  

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.

使用sed(1)脚本进行编辑将变得很脆弱,如果XML的输出或格式发生变化,可能会很容易破坏。

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.

相反,请查看xmlstarlet http://xmlstar.sourceforge.net/以获取与XML文件一起使用的类似工具。它可能已经在您的发行版中,但可能尚未安装。