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/bash
if [ $# -eq 0 ]; then
echo "parameter error"
exit
fi
str=$1
num=$(echo $str |wc -c)
i=1
while [ $i -lt $num ]; do
substr=$( echo $str|cut -c $i-$((i+1)) )
echo -en "\x$substr"
i=$((i+2))
done
echo
refer:
http://stackoverflow.com/questions/1604765/linux-shell-scripting-hex-string-to-bytes