Ascii/Hex convert in bash

前端 未结 15 1467
广开言路
广开言路 2020-12-12 21:03

I\'m now doing it this way:

[root@~]# echo Aa|hexdump -v
0000000 6141 000a                              
0000003
[root@~]# echo -e \"\\x41\\x41\\x41\\x41\"
A         


        
15条回答
  •  感情败类
    2020-12-12 21:28

    Text2Conv="Aa"
    for letter in $(echo "$Text2Conv" | sed "s/\(.\)/'\1 /g");do printf '%x' "$letter";done
    

    4161

    The trick is using sed to parse the Text2Conv to format we can then seperate anf loop using for.

提交回复
热议问题