如何去壳code URL-CN codeD字符串? [英] How to decode URL-encoded string in shell?
本文介绍了如何去壳code URL-CN codeD字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用户代理这是EN codeD列表的文件。
例如:
的Mozilla%2F5.0%20%28Macintosh%3B%20U%3B%20Intel%20Mac%20OS%20X%2010.6%3B%20en
我想一个shell脚本可以读取该文件,并写入与德codeD字符串的新文件。
的Mozilla / 5.0(在Macintosh; U;英特尔的Mac OS X 10.6; EN
我一直在试图用这个例子来得到它去,但它至今没有工作。
$回声-e$(回声%31 +%32%0A%33 +%34| sed的'Y / + / /; S /%/ \\\\点¯x /G')
我的脚本是这样的:
#!/斌/庆典
在* .LOG F;做
回声-e$(猫$ F | sed的'Y / + / /; S /%/ \\ X / G')> y.log
DONE
解决方案
GNU AWK
#!的/ usr / bin中/ AWK -fn
@includeORD
开始 {
RS =%..
}
{
printf的RT? $ 0个CHR(0XSUBSTR(RT,2)):$ 0
}
或者
#!/ bin / sh的
AWK -niord'{printf的RT $ 0chr(0XSUBSTR(RT,2)):$ 0}'RS =%..
I have a file with a list of user-agents which are encoded. E.g.:
Mozilla%2F5.0%20%28Macintosh%3B%20U%3B%20Intel%20Mac%20OS%20X%2010.6%3B%20en
I want a shell script which can read this file and write to a new file with decoded strings.
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en
I have been trying to use this example to get it going but it is not working so far.
$ echo -e "$(echo "%31+%32%0A%33+%34" | sed 'y/+/ /; s/%/\\x/g')"
My script looks like:
#!/bin/bash
for f in *.log; do
echo -e "$(cat $f | sed 'y/+/ /; s/%/\x/g')" > y.log
done
解决方案
GNU awk
#!/usr/bin/awk -fn
@include "ord"
BEGIN {
RS = "%.."
}
{
printf RT ? $0 chr("0x" substr(RT, 2)) : $0
}
Or
#!/bin/sh
awk -niord '{printf RT?$0chr("0x"substr(RT,2)):$0}' RS=%..
Using awk printf to urldecode text
这篇关于如何去壳code URL-CN codeD字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文