Skip to main content
nerdbynature
    • Archives
    • Tags
    • RSS feed
    • Atom feed
    • Imprint

    tr: Illegal byte sequence

    CK

    2010-04-11 10:04

    $ 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
    
    • Newer posts
    • Older posts
    Contents © 2023 CK - Powered by Nikola