URL 编码/解码方法(linux shell实现),方法如下:
1、编码的两种方法:
admin@~ 11:14:29>echo '手机' | tr -d ' ' | xxd -plain | sed 's/(..)/%1/g' admin@~ 11:14:29>echo '手机' |tr -d ' ' |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])/\x2/g')" "
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])/\x2/g' http://i.cnblogs.com/PostDone.aspx?postid=5646871&actiontip=xE4xBFx9DxE5xADx98xE4xBFxAExE6x94xB9xE6x88x90xE5x8Ax9F
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])/\x2/g')" " 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])/\x2/g')" " done