- [root@centos6-1 txt]#
- [root@centos6-1 txt]# ls
- 1.txt 2.txt test.sh
- [root@centos6-1 txt]#
- [root@centos6-1 txt]# sh test.sh
- {["e294c2","344290","alarm","observe"],["1f7f03","112503","index","forecast3d","observe"],["d30b9f","793989","alarm","index","forecast5d","observe"],["a1b42a","4","forecast5d","forecast3h","observe"],["68faa3","648700","alarm","forecast3h","HBxzxxz","forecast","HBgqxx"],["320723","556525","alarm","index","forecast","observe"],["45029b","1424","forecast1d"],["16c070","2063","forecast1d"],["7c1429","12555279","index","forecast5d","observe"],["5aae5b","257","index","forecast3d","observe"],["c8d6bf","55786","index","forecast4d","air","indexen","forecast1d","observe"],["d5881d","256753","air","observe"],["c9f204","8472773","forecast5d","observe"],["71f520","3846","index","forecast3d","air"],["334cfc","5868","alarm","index","forecast3d"],["2389f4","483317","alarm","index","forecast3d","observe"],["f63d32","27917886","index","all","forecast3h","temp","forecast","observe"],["549d81","4294875","alarm","index","calendar","forecast","observe"],["cf2d61","5","index","forecast3d","observe"],["3d274c","185571","observe"],["674c66","716","alarm","index","air","forecast","observe"],["f1c3f8","36","index","forecast3d","observe"],["aa2f1a","2294","forecast5d"],["d7d2bc","79828","observe"],["d229f3","7","forecast5d"],["7d34f2","107","index","forecast3d","observe"],["e9b455","147434","alarm","index","forecast5d","newsw7","newsl7","observe"],["22c100","18","air"],["abb2c8","705","forecast3d"],["7f9b82","5501","index","forecast3d","observe"],["589a93","1","observe"],["7b0712","1","forecast"],["8db47c","3999","forecast","observe"],["5b9529","43258","index","null","forecast3d","observe"],["61.4.184.91","5587005"],["61.4.184.82","17114"],["61.4.184.90","5591422"],["61.4.184.81","5596914"],["61.4.184.83","17132"],["61.4.184.92","5609534"],["61.4.184.93","5601377"],["61.4.184.81","5823231"],["61.4.184.83","17153"],["61.4.184.93","5814682"],["61.4.184.91","5808807"],["61.4.184.82","17173"],["61.4.184.90","5798252"],["222.186.34.74","6"],["222.186.58.141","1"],["61.4.184.92","5810188"],["198.143.149.145","2"]}
- [root@centos6-1 txt]#
- [root@centos6-1 txt]#
- [root@centos6-1 txt]# cat test.sh
- #!/bin/bash
- cat *.txt | awk '/^[0-9]+\./{print > "ipdata";next}!/^$/{print >"indexdata"}'
- awk '$1=="id:"{
- s=$2;
- while(++i<=2){;
- getline l;
- gsub(/^[^ ]+ /,"",l);
- s=s" "l;
- }
- print gensub(/, /,",","g",s);
- i=0;
- }' indexdata | awk '{ a[$1]+=$2;b[$1]=b[$1]?b[$1]","$3:$3 } END {
- for(i in a){
- lens=split(b[i],tp,",");
- for(j=1;j<=lens;j++)tps[tp[j]];
- for(k in tps)vs=vs?vs","k:k;
- print i,a[i],vs;
- vs="";
- delete tps;
- }}' > index
- cat index ipdata | sed 's/[ \t]\+/,/g;s/[A-Za-z0-9.]\+/"&"/g;s/.*/[&]/g' | paste -s -d ',' | sed 's/.*/{&}/g'
- rm -f index ipdata indexdata
- [root@centos6-1 txt]#
- [root@centos6-1 txt]#
复制代码 不知道是不是你要的结果,你试试看。 |