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++):

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

관련 정보