0

I have a file myFile.xmlwhich I want to run the xmllintcommand on for proper formatting.

It contains the ASCII character 26 (substitute char) because of which xmllint command is failing with parser error.

How can I replace all occurrences of this character with blank in this file?

Vicky
  • 16,679
  • 54
  • 139
  • 232

2 Answers2

1

The following worked:

tr -cd '\11\12\15\40-\176' < file-with-binary-chars > clean-file

referred from here:

ascii-control-characters

Vicky
  • 16,679
  • 54
  • 139
  • 232
  • You should probably add to your answer that this command not only substitutes ASCII character 26 (decimal), but also every character not in the set `'\11\12\15\40-\176'` (octal). –  Dec 04 '13 at 10:24
  • Actually it _doesn't_ remove character 26, as this would be `\32` in octal notation. But the road is clear. – Alfe Dec 04 '13 at 10:34
  • 1
    @Alfe It does. The `-c` is for complement and `-d` is for delete. And of course, there's no such thing as a `26` character, just the ASCII value. –  Dec 04 '13 at 10:44
0

If you are using bash, how about this:

sed $'s/\x1a//g' < FILENAME | xmllint

This uses the special bash notation $'...' which tells the bash to evaluate backslash sequences like the \x1a properly.

Alfe
  • 56,346
  • 20
  • 107
  • 159