and vice versa.
I am running a RedHat if relevant.
and vice versa.
I am running a RedHat if relevant.
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
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.
In order to change file endianess, assuming word (32-bit) size, this 1 liner should work for you:
hexdump -v -e '1/4 "%08x"' -e '"\n"' input_file | xxd -r -p > output_file
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.