Index . 블로그창고 . Any comments?

한줄짜리 urldecode 스크립트

urldecode for shell script

오랜만에 블로그를 훈훈한 삽질로 채워본다. Heiner Steven의 awk 버전이 더 빠른지 여기에 소개하는 awk 버전이 더 빠른지는 모르겠으나 최소한 한 줄로 늘어놓으면 더 짧다. -.-;;

$ alias urldecode="awk '"'BEGIN{for(i=0;i<10;i++)hex[i]=i;hex["A"]=hex["a"]=10;hex["B"]=hex["b"]=11;hex["C"]=hex["c"]=12;hex["D"]=hex["d"]=13;hex["E"]=hex["e"]=14;hex["F"]=hex["f"]=15;}{gsub(/\+/," ");i=$0;while(match(i,/%../)){;if(RSTART>1);printf"%s",substr(i,1,RSTART-1);printf"%c",hex[substr(i,RSTART+1,1)]*16+hex[substr(i,RSTART+2,1)];i=substr(i,RSTART+RLENGTH);}print i;}'"'"

$ echo "%31+%32%0A%33+%34" | urldecode
1 2
3 4

보기 좋은 코드는 여기에 있다.

tag:
블로그창고 . 댓글문법

All the works in this site except software and copyrighted materials by others (e.g., 문학) are licensed under a Creative Commons License. 소프트웨어 및 문학과 같이 다른 이에게 저작권이 있는 작품을 제외하고 모두 크리에이티브 커먼즈 라이센스를 따른다.
Mon Mar 25 01:06:08 2024 . XHTML . CSS (lightbox.css is not part of Uniqki. ;-) . Powered by Uniqki!
refresh . edit . loginout . index