Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xmlstarlet - removing linefeed

I have the following file log.xml:

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

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

The result is:

Line 1@  Line 2 and so on

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

I'll receive:

Line 1
  Line 2 nd so on

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

Any ideas how to fix it?

UPDATE

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

like image 823
dimba Avatar asked Feb 19 '13 08:02

dimba


1 Answers

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
like image 65
Pablo Pozo Avatar answered Sep 20 '22 19:09

Pablo Pozo