Conversão decimal em sed

1
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:.*,\).*$//i'

A saída é como

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

Em primeiro lugar, não entendo porque UID:null, aparece na minha saída quando não a incluo no meu código.

Em segundo lugar, quero converter tudo depois de Port: e antes do próximo , a ser exibido em decimal, não sei qual formato está sendo impresso em .

O resultado deve ser como

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

Eu quero que o número da porta seja exibido em vez do que está sendo impresso agora. Não sei se 'c39' corresponde a '8080' aqui . Mas espero que você tenha entendido.

    
por GypsyCosmonaut 19.07.2017 / 11:53

1 resposta

1

Solução complexa usando ferramentas adequadas ( grep + jq + 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=','

A saída:

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
    
por 19.07.2017 / 12:58

Tags