-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathawk-merge.txt
31 lines (27 loc) · 2.28 KB
/
awk-merge.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
➜ ~ cat /tmp/dev-xu-dev-private-access-hardcode.txt
wgdc-drn-03.cloud.xu.domain. 300 IN A 192.168.192.13
apps.cf.wgdc-drn-03.cloud.xu.domain. 300 IN A 192.168.192.197
04.cloud.xu.domain. 300 IN A 192.168.192.222
04.cloud.xu.domain. 300 IN A 192.168.192.223
04.cloud.xu.domain. 300 IN A 192.168.192.221
➜ ~ cat /tmp/dev-xu-dev-private-access-hardcode.txt|awk '{S[$1]=$5","S[$1]}END{for (a in S) print a, S[a]}'|sed 's/,$//g'
wgdc-drn-03.cloud.xu.domain. 192.168.192.13
apps.cf.wgdc-drn-03.cloud.xu.domain. 192.168.192.197
04.cloud.xu.domain. 192.168.192.221,192.168.192.223,192.168.192.222
尝试理解上面
S[$1] 代表对第一列操作
S[$1]=$5 若第一列内容相同 对5列
cat /tmp/c.txt
www.baidu.com 14.215.177.39 14.215.177.38
www.gitee.com 180.97.125.228
www.gitee.com 180.97.125.229
www.sina.com.cn 124.116.156.30 124.116.156.28 124.116.156.27 118.182.230.187 61.159.95.125 61.159.95.124 61.159.95.123
www.sohu.com 119.96.200.204
www.toutiao.com 219.144.108.231 219.144.108.230 219.144.108.229 219.144.108.228 219.144.108.227 219.144.108.226 219.144.108.225 219.144.108.224 113.137.56.189 113.137.56.187 113.137.54.230 113.137.54.228 113.137.54.227 113.137.54.224 113.137.54.195 113.137.54.193
www.toutiao.com 219.144.108.231 219.144.108.230 219.144.108.229 219.144.108.228 219.144.108.227 219.144.108.226 219.144.108.225 219.144.108.224 113.137.56.252 113.137.56.236 113.137.54.230 113.137.54.229 113.137.54.228 113.137.54.226 113.137.54.197 113.137.54.193
cat /tmp/c.txt| sort|uniq|awk '{x=$1;$1="";S[x]=$0" "S[x]} END {for (a in S) print a, S[a]}'|sort -k1
www.baidu.com 14.215.177.39 14.215.177.38
www.gitee.com 180.97.125.229 180.97.125.228
www.sina.com.cn 124.116.156.30 124.116.156.28 124.116.156.27 118.182.230.187 61.159.95.125 61.159.95.124 61.159.95.123
www.sohu.com 119.96.200.204
www.toutiao.com 219.144.108.231 219.144.108.230 219.144.108.229 219.144.108.228 219.144.108.227 219.144.108.226 219.144.108.225 219.144.108.224 113.137.56.252 113.137.56.236 113.137.54.230 113.137.54.229 113.137.54.228 113.137.54.226 113.137.54.197 113.137.54.193 219.144.108.231 219.144.108.230 219.144.108.229 219.144.108.228 219.144.108.227 219.144.108.226 219.144.108.225 219.144.108.224 113.137.56.189 113.137.56.187 113.137.54.230 113.137.54.228 113.137.54.227 113.137.54.224 113.137.54.195 113.137.54.193