shell split分析日志文件
在處理的文件comment有如下格式:
............................
xxx.xxx.10.59 db1059 mynbdpdatadb.idc4. dbname R620 master IDC2 Y Y Y
xxx.xxx.11.59 db1159 mynbdpdatadw.idc4. dbname R620 slave IDC1 Y Y Y
xxx.xxx.10.90 db1090 - dbname1,dbname2,dbname3 R620 slave IDC3 Y Y Y
xxx.xxx.11.90 db1190 - dbname1,dbname2,dbname3 R620 slave IDC2 Y Y Y
xxx.xxx.10.94 db1094 myuetdb.idc4. dbname Gen8 master IDC1 Y Y Y
................................
要分析如下 ip 主機名 域名 schema 主機硬件設備 主/從 機房 其他是否是否監控
shell腳本分析如下:
cat /tmp/comment |awk'{split($1,key1,".");split($2,key2,"|");{if(key2[3]=="")key2[3]="-"};{if(key2[4]=="")key2[4]="-"};{if(key2[5]=="")key2[5]="-"};print $1,"db"key1[3]key1[4],key2[4],key2[3],key2[5],key2[2],key2[6],"Y","Y","Y"}'>/root/fenxi.txt