convert HEX to Char

来源:互联网 发布:python 列表与元组 编辑:程序博客网 时间:2024/05/13 12:04

perl:

trim non-HEX chars

echo 333961363a73746f72616765746965725f7573616765 | perl -ne 's/([0-9a-f]{2})/print chr hex $1/gie'


not convert non-HEX chars

echo -n 333961363a73746f72616765746965725f757361676566\ 66 | perl -pe 's/([0-9a-f]{2})/chr hex $1/gie'

xxd:

echo 333961363a73746f72616765746965725f7573616765 |xxd -r -p

shell:

#!/bin/bashif [ $# -eq 0 ]; then    echo "parameter error"    exitfistr=$1num=$(echo $str |wc -c)i=1while [ $i -lt $num ]; do    substr=$( echo $str|cut -c $i-$((i+1)) )    echo -en "\x$substr"    i=$((i+2))doneecho 

refer:

http://stackoverflow.com/questions/1604765/linux-shell-scripting-hex-string-to-bytes

0 0
原创粉丝点击