Search code examples
fileunixreplacecharacternon-printing-characters

Replacing all occurrences of non-printable character in a file using its ascii value


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?


Solution

  • The following worked:

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

    referred from here:

    ascii-control-characters