chhj_292 发表于 2013-12-20 10:46

如何将 shell 结果合并成一行?

shell 1:
www:Desktop qshl$ wget -qc http://pachong.org/ -O - | grep -o '\d\+\.\d\+\.\d\+\.\d\+'
120.84.236.250
202.118.236.130
...

shell 2:
www:Desktop qshl$ wget -qc http://pachong.org/ -O - | grep -o '<td>\d\{2,5\}</td>' | grep -o '\d\{2,5\}'
8080
7777
...

请问,如何将结果合并成 120.84.236.250:8080 形式?

或者是否有更好的方法?

WilliBhamlll 发表于 2013-12-20 11:05

没仔细看,根据实际情况再改改吧paste -d":" <(wget -qc http://pachong.org/ -O -|grep -Po '(\d+\.){3}\d+') <(wget -qc http://pachong.org/ -O -|grep -Po '(?<=td>)\d+')

WilliBhamlll 发表于 2013-12-20 11:05

本帖最后由 WilliBhamlll 于 2013-12-20 11:06 编辑

卡了一下,回重复了。

chhj_292 发表于 2013-12-20 11:14

非常感谢,paste 还是我第一次见。
grep 的 -P 参数 Darwin 内核好像不支持?

要是能一个请求就能分析出结果是最好的,把结果集中的空白字符都去掉,然后用正则匹配出 ip 和 port 规则,再 sed 一下。
就是可能有点复杂。

回复 3# WilliBhamlll


   

chhj_292 发表于 2013-12-20 11:17

回复 2# WilliBhamlll

操作系统:
Max OS X 10.8.3

内核信息:
www:Desktop qshl$ uname -a
Darwin localhost 12.3.0 Darwin Kernel Version 12.3.0: Sun Jan6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64
www:Desktop qshl$ grep -P
usage: grep [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C]
        [-e pattern] [-f file] [--binary-files=value] [--color=when]
        [--context[=num]] [--directories=action] [--label] [--line-buffered]
        [--null]


   

lxzkenney 发表于 2013-12-20 11:24

nbrr 发表于 2013-12-20 11:30

本帖最后由 nbrr 于 2013-12-20 11:34 编辑

用sed写了个,应该还有更好的方法
wget -qc http://pachong.org/ -O - | sed -n -r -e 's@.*<td>(+\.+\.+\.+|{2,5})<\/td>.*@\1@p' | sed 'N;s@\n@:@'

yinyuemi 发表于 2013-12-20 11:31

回复 1# chhj_292

wget -qc http://pachong.org/ -O - | sed -n '/^\s\+<td>\(\(\+\.\)\{3\}\+\)<\/td>/{s//\1/;h;n;s/.*<td>\(\+\)<\/td>/\1/;H;x;s/\n/:/p}'

WilliBhamlll 发表于 2013-12-20 11:34

本帖最后由 WilliBhamlll 于 2013-12-20 11:40 编辑

回复 5# chhj_292 wget -qc http://pachong.org/ -O - | grep -EA1 '({1,3}\.){3}{1,3}'|awk -vRS="[</td>\n]" 'NF'|sed '/--/d;N;s/\n/:/'
61.156.217.135:9000
202.203.17.82:3128
61.147.82.87:8000
219.159.199.6:9999
211.141.125.56:3128
118.244.195.43:80
221.192.152.16:80
120.84.236.250:8080
60.190.138.151:80
118.112.54.141:8080
123.103.23.106:20648
222.139.5.210:9000
58.242.249.14:18186
218.107.4.117:1080
58.39.24.230:8080
218.28.121.22:9999
61.143.124.155:80
222.87.129.30:80
60.12.150.221:8080
203.64.251.80:8080
219.150.204.30:8080
202.118.236.130:7777
124.163.222.76:80
121.9.231.82:9999
60.223.255.141:8080
110.80.37.250:9999
218.93.112.72:3128
116.112.66.102:808
221.10.102.199:83
111.11.27.36:80
203.150.19.219:3128
221.181.192.60:80
122.96.59.100:81
219.145.145.7:8888
61.158.219.226:8118
219.219.62.238:3080
41.205.93.18:8080
186.67.21.142:8080
217.192.57.231:80
199.185.61.1:8081
177.136.224.17:8080
190.186.159.78:8080
83.244.111.18:8080
151.237.37.177:8080
111.221.2.134:8080
109.175.6.192:8080
190.189.124.224:8080
212.34.236.62:8080
109.104.144.18:8082
94.201.134.251:80

jason680 发表于 2013-12-20 11:37

回复 5# chhj_292

>>grep 的 -P 参数 Darwin 内核好像不支持?

supported
usage: grep [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C]
   
页: [1] 2
查看完整版本: 如何将 shell 结果合并成一行?