以下是根据避难所的建议更改的输入数据。如果现在可以处理,请支持
> Aug 25 17:21:39 DL_2_11 dpat[999]: tons=1012 op=586988 OPER=RESERCH ANSWER tag=101 usr=80 nentries=0 description=Read usror on tonsection to target req=serv=psts,TMUnitTroup=10,cmsId=511a3f0345bb4030acfccdb7b7d308b6,pu=multiple,SUBTNode=21,pt=pmp filter=(objectClass=*)
Aug 25 17:21:39 DL_2_11 dpat[999]: tons=1012 op=586988 OPER=RESERCH ANSWER tag=101 usr=80 nentries=0 description=Read usror on tonsection to target req=serv=psts,TMUnitTroup=10,cmsId=511a3f0345bb4030acfccdb7b7d308b6,pu=multiple,SUBTNode=21,pt=pmp filter=(objectClass=*)
Aug 25 17:21:39 DL_2_11 dpat[999]: tons=1012 op=586988 OPER=RESERCH ANSWER tag=101 usr=80 nentries=0 description=Read usror on tonsection to target req=serv=psts,TMUnitTroup=10,cmsId=511a3f0345bb4030acfccdb7b7d308b6,pu=multiple,SUBTNode=21,pt=pmp filter=(objectClass=*)
Aug 25 17:21:39 DL_2_11 dpat[999]: tons=1012 op=586988 OPER=RESERCH ANSWER tag=101 usr=80 nentries=0 description=Read usror on tonsection to target req=serv=psts,TMUnitTroup=10,cmsId=511a3f0345bb4030acfccdb7b7d308b6,pu=multiple,SUBTNode=21,pt=pmp filter=(objectClass=*)
Aug 25 17:21:39 DL_2_11 dpat[999]: tons=1012 op=586988 OPER=RESERCH ANSWER tag=101 usr=80 nentries=0 description=Read usror on tonsection to target req=serv=psts,TMUnitTroup=10,cmsId=511a3f0345bb4030acfccdb7b7d308b6,pu=multiple,SUBTNode=21,pt=pmp filter=(objectClass=*)
Aug 25 17:21:39 DL_2_11 dpat[999]: tons=1012 op=586988 OPER=RESERCH ANSWER tag=101 usr=80 nentries=0 description=Read usror on tonsection to target req=serv=psts,TMUnitTroup=10,cmsId=511a3f0345bb4030acfccdb7b7d308b6,pu=multiple,SUBTNode=21,pt=pmp filter=(objectClass=*)重试
awk 'BEGIN {
HCNT = split("OPER|usr|description|req|TMUnitTroup|SUBTNode", COLN, "|")
TMP = split("40 40 40 18 10 14 23", FLEN, FS)
FMT = "%-*.*s "
for (i = 1; i <= HCNT; i++) {
printf FMT, FLEN[i], FLEN[i], COLN[i]
}
printf "Count" ORS
}
{
OUT = ""
for (i = 1; i <= HCNT; i++) {
match($0, COLN[i] "[^ ]*")
TMP = substr($0, RSTART, RLENGTH)
sub(/^[^ ,]*= /, _, TMP)
OUT = OUT sprintf(FMT, FLEN[i], FLEN[i], TMP)
}
T[OUT]++
}
END {
for (t in T) {
print t, T[t]
}
}' tudberr
OPER usr description req TMUnitTrou SUBTNode Count我希望这次我的awk代码可读.Here是输入文件。
Aug 25 17:21:39 DL_2_11 dpat[999]: tons=1012 op=586988 RESERCH ANSWER tag=101 usr=80 nentries=0 description=Read usror on tonsection to target req=serv=psts,TMUnitTroup=10,cmsId=1234asdbfghueikjla5342789157b3,pu=multiple,SUBTNode=21,pt=pmp filter=(objectClass=*)
Aug 25 17:21:39 DL_2_11 dpat[999]: tons=1012 op=586988 RESERCH ANSWER tag=101 usr=80 nentries=0 description=Read usror on tonsection to target req=serv=psts,TMUnitTroup=10,cmsId=1234asdbfghueikjla5342789157b3,pu=multiple,SUBTNode=21,pt=pmp filter=(objectClass=*)
Aug 25 17:21:39 DL_2_11 dpat[999]: tons=1012 op=586988 RESERCH ANSWER tag=101 usr=80 nentries=0 description=Read usror on tonsection to target req=serv=psts,TMUnitTroup=10,cmsId=1234asdbfghueikjla5342789157b3,pu=multiple,SUBTNode=21,pt=pmp filter=(objectClass=*)
Aug 25 17:21:39 DL_2_11 dpat[999]: tons=1012 op=586988 RESERCH ANSWER tag=101 usr=80 nentries=0 description=Read usror on tonsection to target req=serv=psts,TMUnitTroup=10,cmsId=1234asdbfghueikjla5342789157b3,pu=multiple,SUBTNode=21,pt=pmp filter=(objectClass=*)
Aug 25 17:21:39 DL_2_11 dpat[999]: tons=1012 op=586988 RESERCH ANSWER tag=101 usr=80 nentries=0 description=Read usror on tonsection to target req=serv=psts,TMUnitTroup=10,cmsId=1234asdbfghueikjla5342789157b3,pu=multiple,SUBTNode=21,pt=pmp filter=(objectClass=*)
Aug 25 17:21:39 DL_2_11 dpat[999]: tons=1012 op=586988 RESERCH ANSWER tag=101 usr=80 nentries=0 description=Read usror on tonsection to target req=serv=psts,TMUnitTroup=10,cmsId=1234asdbfghueikjla5342789157b3,pu=multiple,SUBTNode=21,pt=pmp filter=(objectClass=*)我需要通过读取上述文件生成以下输出。输出应该在如下所示的列中,以总结此日志。
op usr description req TMUnitTroup SUBTNode COUNT
RESERCH 80 Read usror on tonsection to target serv=psts 10 21 6我尝试了下面的代码,但输出结果并不完全符合我的需要
awk 'BEGIN {
HCNT = split("op|usr|description|req|TMUnitTroup|SUBTNode", COLN, "|")
TMP = split("40 40 40 18 10 14 23", FLEN, FS)
FMT = "%-*.*s "
for (i = 1; i <= HCNT; i++) {
printf FMT, FLEN[i], FLEN[i], COLN[i]
}
printf "Count" ORS
}
{
OUT = ""
for (i = 1; i <= HCNT; i++) {
match($0, COLN[i] "[^ ]*")
TMP = substr($0, RSTART, RLENGTH)
sub(/^[^ ,]*= /, _, TMP)
OUT = OUT sprintf(FMT, FLEN[i], FLEN[i], TMP)
}
T[OUT]++
}
END {
for (t in T) {
print t, T[t]
}
}' tudberr
Output i got is
op usr description req TMUnitTrou SUBTNode Count
op=586988 usr=80 description=Read req=serv=psts,TMUn TMUnitTrou SUBTNode=21,pt 6
1发布于 2020-08-26 14:48:20
正如shellter所说,“让你的数据更容易处理”:
awk '{ s="";
j=0;
for(i=1; i<=NF; i++) { if(index($i,"=")==0)
{k[j]=k[j] FS $i }
else k[++j]=$i; };
for(i in k){ print i,k[i] }
delete k; print "" }' tudberr这将输出(对于输入文件的前3行):
0 Aug 25 17:21:39 DL_2_11 dpat[999]:
1 tons=1012
2 op=586988 RESERCH ANSWER
3 tag=101
4 usr=80
5 nentries=0
6 description=Read usror on tonsection to target
7 req=serv=psts,TMUnitTroup=10,cmsId=1234asdbfghueikjla5342789157b3,pu=multiple,SUBTNode=21,pt=pmp
8 filter=(objectClass=*)
0 Aug 25 17:21:39 DL_2_11 dpat[999]:
1 tons=1012
2 op=586988 RESERCH ANSWER
3 tag=101
4 usr=80
5 nentries=0
6 description=Read usror on tonsection to target
7 req=serv=psts,TMUnitTroup=10,cmsId=1234asdbfghueikjla5342789157b3,pu=multiple,SUBTNode=21,pt=pmp
8 filter=(objectClass=*)
0 Aug 25 17:21:39 DL_2_11 dpat[999]:
1 tons=1012
2 op=586988 RESERCH ANSWER
3 tag=101
4 usr=80
5 nentries=0
6 description=Read usror on tonsection to target
7 req=serv=psts,TMUnitTroup=10,cmsId=1234asdbfghueikjla5342789157b3,pu=multiple,SUBTNode=21,pt=pmp
8 filter=(objectClass=*)这个输出应该更容易处理...
https://stackoverflow.com/questions/63588502
复制相似问题