Search code examples
bashxxd

How to make a hexdump line by line with xxd?


To create sample file with cat.

cat > /tmp/test.txt <<EOF
> X1
> X22
> X333
> X4444
> EOF

To check the content in sample file.

cat  /tmp/test.txt
X1
X22
X333
X4444

To make a hexdump with xxd.

xxd   /tmp/test.txt
0000000: 5831 0a58 3232 0a58 3333 330a 5834 3434  X1.X22.X333.X444
0000010: 340a  

How to make a hexdump line by line with xxd in such way as below:

58 31 0a
58 32 32 0a
58 33 33 33 0a
58 34 34 34 34 0a

Solution

  • After all I found the hexdump tool in combination with sed the best solution:

    hexdump -v -e '/1 "%02x "' /tmp/test.txt | sed 's/0a /0a\n/g'