1

This isn't a deploy related question, but I believe it belongs here.

I've found out about the od tool yesterday, and began to fiddle with it.

The question is about utf-8 encoding. See the examples:

~ $ echo -n á | od -x
0000000 a1c3
0000002
~ $ echo -n áá | od -x
0000000 a1c3 a1c3
0000004
~ $ echo -n ác | od -x
0000000 a1c3 0063
0000003

# This is the issue
~ $ echo -n cá | od -x
0000000 c363 00a1
0000003

So á translates to c3 a1 correctly in each test besides the last, which begins with an ascii char. Why isn't the output of the last test 0063 a1c3 (i.e. invert the one before the last) ?

I've tried to read from a utf-8 file and the result is the same.

Thanks in advance.

2 Answers 2

1

Problem solved:

It's because of endianess of output.

There is an option --endian which by default is little.

The example string was , which translates to 63 C3 A1 utf-8 encoded:

~ $ echo -n cá | od --endian=big -x
0000000 63c3 a100
0000003

(The -n prevents \n in the end of string, making last byte 00)

So it's exactly the same output, but with bytes inverted:

~ $ echo -n cá | od --endian=little -x
0000000 c363 00a1
0000003

(c363 instead of 63c3 and so forth).

1

Because of endianess and other things I've settled on these two aliases I use all the time. The important thing is -t x1

alias od1='od -Ax -t x1'
alias od2='od -Ax -t x1 -c'
3
  • -Ax is for accepting hex offsets in params right ? But then, the od2's -c means -t c and overrides -t x1, so od2 could just be od -Ax -c.
    – Niloct
    Nov 2, 2020 at 15:22
  • You might like this better: od -ctx1. Or use hexdump -C (maybe available via hd), or xxd. To answer the implied question in the post's title: "Yes, it is".
    – jrw32982
    Nov 5, 2020 at 18:04
  • @Niloct -Ax is to output the file offsets in hex. -t x1 doesn't negate the -c although I see why you would think that. Nov 12, 2020 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.