Search code examples
linuxshellhex

Linux script to convert byte data into a hex string


I have byte data,

0Y0*†HÎ*†HÎ=B¬`9E>ÞÕ?ÐŽ·‹ñ6ì­Â‰&ÉÐL_cüsyxoú¢
†
(¯-›E–¿9ÐÖ1ªÐ›¯o

Now, I want to create one Linux script that will convert that data into a hex string. How can I do that?


Solution

  • Should you want only the hex strings:

    $ echo '0Y0*†HÎ*†HÎ=B¬`9E>ÞÕ?ÐŽ·‹ñ6ì­Â‰&ÉÐL_cüsyxoú¢'|od -vt x1|awk '{$1="";print}'
     30 59 30 2a e2 80 a0 48 c3 8e 2a e2 80 a0 48 c3
     8e 3d 42 c2 ac 60 39 45 3e c3 9e c3 95 3f c3 90
     c5 bd c2 b7 e2 80 b9 c3 b1 36 c3 ac c2 ad c3 82
     e2 80 b0 26 c3 89 c3 90 4c 5f 63 c3 bc 73 79 78
     6f c3 ba c2 a2 0a
    

    You can avoid the awk part by just using od -vt x1 -A n. Thanks @Stefan van den Akker.