Skip to content

tr: Illegal byte sequence

$ cat /tmp/foo
ÿs
$ tr -d \r < /tmp/foo 
tr: Illegal byte sequence
Whoops? Let's take a closer look:
$ od -x /tmp/foo 
0000000      73ff    0a0d
0000004
So, it's some unicode character (0xff), a small "s" (0x74), then a CR (0x0d, which I'm trying to remove) and a newline (0x0a) at the end. Turns out it's how MacOS 10.6 handles unicode characters. Specifying a different locale seems to help:
$ LC_CTYPE=C tr -d \r < /tmp/foo 
ÿs