manually adding BOM to UTF-16LE file?

hi.

i have a bash script that needs to preform something on a string from standard input, save it in a file and convert the file to UTF-16LE with BOM for further processing by another application.

i use iconv to convert the text file to UTF-16LE, but iconv actually creates a little-endian file WITHOUT the bom. (converting to UTF-16 creates a big endian file WITH bom)

i see no way of creating LE with BOM with iconv, so i thought maybe i could simply add the byte-order marks (FF FE) to the beginning of the unicode file. how can i do that?

many thanks in advance
tench

Mac Pro, Mac OS X (10.5.2)

Posted on Nov 18, 2008 12:34 AM

Reply
3 replies

Nov 18, 2008 7:35 AM in response to Merged Content 1

If you want to do everything from within bash script, then you can use something like
{code}
#!/bin/sh
# I think xpg_echo is ON by default, but just in case...
shopt -s xpg_echo
cat > infile
# assume the input is in UTF-8
(echo '\xFF\xFE\c'
iconv -f UTF-8 -t UTF-16LE infile) > outfile
{code}
Of course use of infile can be omitted if you don't need it.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

manually adding BOM to UTF-16LE file?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.