Is there a oneliner that converts a binary file from little endian to big endian?

You cannot do this because for such a conversion, you need to know the meaning of the binary content.

If e.g. there is a string inside a binary file it must not be converted and a 4 byte integer may need different treatment than a two byte integer.

In other words, for a byte order conversion, you need a data type description.


You can byteswap with dd. Is that sufficent? If not, please update your question to give an example of an input file and the expected outfile.

echo hello >infile
dd conv=swab <infile >outfile

hex infile
   0000 68 65 6c 6c 6f 0a                                 hello.
hex outfile
   0000 65 68 6c 6c 0a 6f                                 ehll.o

If you don't care about file contents and just want to swap bytes, then try endconv. It is just a wrapper around standard byte conversion functions, so it supports conversion by 2, 4 and 8 byte long integers. It's not one liner though because it is separate program.

Tags:

Byte