sed 中的十进制转换

sed 中的十进制转换
curl www.gatherproxy.com | sed '1,61d; 210,$d; /script/d' | sed 's/^\s*//; s/"//g; s/proxy_//gi; 0~1 a\\' | sed 's/.*\(country.*,\)\(ip:.*,\).*,\(port:.*,\).*,.*,\(status:.*,\).*,\(type:.*,\).*$/\1\2\3\4\5/i'

它的输出就像

COUNTRY:Singapore,IP:180.210.201.59,PORT:C39,STATUS:OK,TYPE:Transparent,UID:null,
                                          ↑                               ↑

首先,我不明白为什么UID:null,当我没有将其包含在代码中时出现在我的输出中。

其次,我想将下Port:一个之后和之前的所有内容转换,为十进制显示,我不知道这是用什么格式打印的

输出应该是这样的

COUNTRY:Singapore,IP:180.210.201.59,PORT:8080,STATUS:OK,TYPE:Transparent

我希望显示端口号而不是现在打印的端口号。我不知道这里的“c39”是否对应于“8080”。但希望你明白了。

答案1

使用适当的工具的复杂解决方案(grep+杰克+awk):

curl www.gatherproxy.com | grep -io '{"proxy_[^}]*}' \
 | jq -r '. | {COUNTRY:.PROXY_COUNTRY, IP:.PROXY_IP,PORT:.PROXY_PORT,STATUS:.PROXY_STATUS,TYPE:.PROXY_TYPE}' -c \
 | sed 's/["{}]//g' | awk -F, '{ p=substr($3,6); $3="PORT:" sprintf("%d",strtonum("0x" p)); }1' OFS=','

输出:

COUNTRY:Canada,IP:47.52.5.8,PORT:3128,STATUS:OK,TYPE:Transparent
COUNTRY:Spain,IP:86.109.100.80,PORT:8080,STATUS:OK,TYPE:Elite
COUNTRY:Indonesia,IP:36.66.38.186,PORT:8080,STATUS:OK,TYPE:Elite
COUNTRY:China,IP:122.112.210.64,PORT:8080,STATUS:OK,TYPE:Elite
COUNTRY:Egypt,IP:41.33.173.130,PORT:8080,STATUS:OK,TYPE:Transparent
COUNTRY:Brazil,IP:179.208.202.130,PORT:80,STATUS:OK,TYPE:Elite
COUNTRY:China,IP:121.42.154.207,PORT:3128,STATUS:OK,TYPE:Elite
COUNTRY:Brazil,IP:179.178.34.129,PORT:8080,STATUS:OK,TYPE:Transparent
COUNTRY:Brazil,IP:187.120.181.172,PORT:8080,STATUS:OK,TYPE:Transparent
COUNTRY:Hong Kong,IP:137.74.5.69,PORT:3128,STATUS:OK,TYPE:Elite
COUNTRY:Brazil,IP:189.107.28.64,PORT:8080,STATUS:OK,TYPE:Transparent
COUNTRY:Brazil,IP:200.198.55.1,PORT:3128,STATUS:OK,TYPE:Transparent
COUNTRY:Brazil,IP:177.103.182.12,PORT:5000,STATUS:OK,TYPE:Transparent
COUNTRY:Germany,IP:62.214.70.116,PORT:3128,STATUS:OK,TYPE:Transparent
COUNTRY:Brazil,IP:189.40.191.95,PORT:8080,STATUS:OK,TYPE:Elite
COUNTRY:Malaysia,IP:161.139.20.49,PORT:8111,STATUS:OK,TYPE:Anonymous
COUNTRY:United States,IP:52.237.24.110,PORT:80,STATUS:OK,TYPE:Anonymous
COUNTRY:Hong Kong,IP:219.76.4.12,PORT:88,STATUS:OK,TYPE:Elite
COUNTRY:Turkey,IP:88.255.150.226,PORT:8888,STATUS:OK,TYPE:Elite
COUNTRY:Russia,IP:92.126.9.142,PORT:8080,STATUS:OK,TYPE:Elite
COUNTRY:Russia,IP:217.119.82.14,PORT:8080,STATUS:OK,TYPE:Elite
COUNTRY:Japan,IP:133.242.237.206,PORT:88,STATUS:OK,TYPE:Elite
COUNTRY:Taiwan,IP:203.74.4.7,PORT:80,STATUS:OK,TYPE:Elite
COUNTRY:Hong Kong,IP:219.76.4.72,PORT:88,STATUS:OK,TYPE:Elite
COUNTRY:France,IP:86.208.110.49,PORT:80,STATUS:OK,TYPE:Elite
COUNTRY:Russia,IP:92.126.21.98,PORT:8080,STATUS:OK,TYPE:Elite
COUNTRY:Russia,IP:62.182.25.38,PORT:8080,STATUS:OK,TYPE:Elite
COUNTRY:Panama,IP:200.108.35.60,PORT:8087,STATUS:OK,TYPE:Elite
COUNTRY:Hong Kong,IP:152.101.20.35,PORT:80,STATUS:OK,TYPE:Elite
COUNTRY:Russia,IP:195.88.23.252,PORT:8080,STATUS:OK,TYPE:Transparent
COUNTRY:Turkey,IP:91.93.132.138,PORT:3128,STATUS:OK,TYPE:Transparent
COUNTRY:Russia,IP:109.75.254.139,PORT:8080,STATUS:OK,TYPE:Elite
COUNTRY:Ukraine,IP:94.130.14.146,PORT:31288,STATUS:OK,TYPE:Anonymous
COUNTRY:Indonesia,IP:180.251.144.71,PORT:80,STATUS:OK,TYPE:Elite
COUNTRY:Colombia,IP:181.143.213.202,PORT:8080,STATUS:OK,TYPE:Elite
COUNTRY:Russia,IP:176.62.77.212,PORT:8080,STATUS:OK,TYPE:Elite
COUNTRY:United Kingdom,IP:88.99.149.188,PORT:31288,STATUS:OK,TYPE:Anonymous
COUNTRY:United States,IP:142.4.204.69,PORT:3128,STATUS:OK,TYPE:Transparent
COUNTRY:Germany,IP:148.251.133.60,PORT:3128,STATUS:OK,TYPE:Elite
COUNTRY:Russia,IP:31.173.218.199,PORT:8080,STATUS:OK,TYPE:Elite
COUNTRY:Italy,IP:178.239.177.210,PORT:80,STATUS:OK,TYPE:Elite
COUNTRY:Russia,IP:95.220.218.24,PORT:8081,STATUS:OK,TYPE:Transparent
COUNTRY:Germany,IP:83.169.17.103,PORT:80,STATUS:OK,TYPE:Anonymous
COUNTRY:Malaysia,IP:221.133.44.142,PORT:8080,STATUS:OK,TYPE:Anonymous
COUNTRY:India,IP:59.145.117.26,PORT:3128,STATUS:OK,TYPE:Transparent
COUNTRY:Bangladesh,IP:180.234.223.91,PORT:8080,STATUS:OK,TYPE:Transparent
COUNTRY:Thailand,IP:183.88.41.150,PORT:8080,STATUS:OK,TYPE:Transparent
COUNTRY:China,IP:223.68.1.38,PORT:8000,STATUS:OK,TYPE:Transparent
COUNTRY:Russia,IP:37.29.107.126,PORT:8080,STATUS:OK,TYPE:Transparent
COUNTRY:United States,IP:144.217.248.180,PORT:8080,STATUS:OK,TYPE:Transparent

相关内容