How can I remove the BOM from a UTF-8 file?

后端 未结 5 1660
忘掉有多难
忘掉有多难 2020-12-06 04:53

I have a file in UTF-8 encoding with BOM and want to remove the BOM. Are there any linux command-line tools to remove the BOM from the file?

$ file test.xml
         


        
5条回答
  •  我在风中等你
    2020-12-06 05:20

    Well, just dealt with this today and my preferred way was dos2unix:

    dos2unix will remove BOM and also take care of other idiosyncrasies from other SOs:

    $ sudo apt install dos2unix
    $ dos2unix test.xml
    

    It's also possible to remove BOM only (-r, --remove-bom):

    $ dos2unix -r test.xml
    

    Note: tested with dos2unix 7.3.4

提交回复
热议问题