How can I re-add a unicode byte order marker in linux?

前端 未结 7 1882
-上瘾入骨i
-上瘾入骨i 2021-02-13 15:22

I have a rather large SQL file which starts with the byte order marker of FFFE. I have split this file using the unicode aware linux split tool into 100,000 line chunks. But whe

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-13 15:39

    To add BOMs to the all the files that start with "foo-", you can use sed. sed has an option to make a backup.

    sed -i '1s/^\(\xff\xfe\)\?/\xff\xfe/' foo-*
    

    straceing this shows sed creates a temp file with a name starting with "sed". If you know for sure there is no BOM already, you can simplify the command:

    sed -i '1s/^/\xff\xfe/' foo-*
    

    Make sure you need to set UTF-16, because i.e. UTF-8 is different.

提交回复
热议问题