xmlstarlet-删除换行 [英] xmlstarlet - removing linefeed

查看:41
本文介绍了xmlstarlet-删除换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下文件 log.xml :

<entry>
  <message>Line 1
  Line 2 and so on</message>
</entry>

在使用xmlstarlet 1.0.1的CentOS 5.4上,如果我运行以下命令,同时删除消息中的换行符:

On CentOS 5.4 using xmlstarlet 1.0.1 if I run the following command, while removing linefeed in message:

xml sel -t -m //entry -v "translate(message,'&#xa;' ,'@')" log.xml

结果是:

Line 1@  Line 2 and so on

在使用xmlstarlet的CentOS 6上:

On CentOS 6 using xmlstarlet:

1.3.1
compiled against libxml2 2.7.6, linked with 20706
compiled against libxslt 1.1.26, linked with 10126

我会收到:

Line 1
  Line 2 nd so on

将注释和"转换为空.我想这不是xmlstarlet的问题,而是libxslt中的一些更改.

Note "and" converted to nothing. I suppose it's not problem of xmlstarlet, but rather some change in libxslt.

有什么想法要解决吗?

更新

添加了将字母"a"转换为空的问题.

Added problem with transform of letter "a" to nothing.

推荐答案

您可以通过定义包含换行符值的变量来以一般方式解决此问题:

You can solve this in a general way by defining a variable containing the value of a line break:

--var linebreak -n --break 

然后使用该变量作为转换函数的第二个参数:

Then use that variable as the second argument of the translate function:

xml sel -t -m //entry
        --var linebreak -n --break
        -v "translate(message, \$linebreak ,'@')"
        log.xml

这篇关于xmlstarlet-删除换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆