sedの10進変換

sedの10進変換
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+ジャック+アッ):

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

関連情報