URL 编码/解码方法(linux shell实现),方法如下:
1、编码的两种方法:
admin@~ 11:14:29>echo '手机' | tr -d '\n' | xxd -plain | sed 's/\(..\)/%\1/g'
admin@~ 11:14:29>echo '手机' |tr -d '\n' |od -An -tx1|tr ' ' %
2、解码的两个步骤:
admin@~ 11:15:11>url="要解码的URL地址"
admin@~ 11:15:11> printf $(echo -n $url | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g')"\n"
saltstack_s:~ $ echo "http://i.cnblogs.com/PostDone.aspx?postid=5646871&actiontip=%E4%BF%9D%E5%AD%98%E4%BF%AE%E6%94%B9%E6%88%90%E5%8A%9F" | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g'
http://i.cnblogs.com/PostDone.aspx?postid=5646871&actiontip=\xE4\xBF\x9D\xE5\xAD\x98\xE4\xBF\xAE\xE6\x94\xB9\xE6\x88\x90\xE5\x8A\x9F
saltstack_s:~ $ url="http://i.cnblogs.com/PostDone.aspx?postid=5646871&actiontip=%E4%BF%9D%E5%AD%98%E4%BF%AE%E6%94%B9%E6%88%90%E5%8A%9F"
saltstack_s:~ $ printf $(echo -n $url | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g')"\n"
http://i.cnblogs.com/PostDone.aspx?postid=5646871&actiontip=保存修改成功
for url in `cat urlfile.txt`
do
printf $(echo -n $url | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g')"\n"
done