我需要以某种方式修改下面的文件:
1445777609670355400 mongo client connection created with mongodb
1445777612279125121 [A], Time(ms), 3344.0
1445777612288777627 [B], Throughput(ops/sec), 299.0430622009569
1445777612289907122 [C], Operations, 505.0
1445777612290864948 [D], AverageLatency(us), 1712.0039603960397
1445777612294065941 [E], MinLatency(us), 253.0
1445777612325747187 [F], Return=0, 505
我按照thread中给出的解决方案。到目前为止我得到了一些结果:
mongodb operations="A" 1445777612279125121
mongodb operations="B" 1445777612288777627
mongodb operations="C" 1445777612289907122
mongodb operations="D" 1445777612290864948
mongodb operations="E" 1445777612294065941
mongodb operations="F" 1445777612295131996
我想实现这个输出:
mongodb operations="A",RunTime(ms)=3344.0 1445777612279125121
mongodb operations="B",Throughput(ops/sec)=299.0430622009569 1445777612288777627
mongodb operations="C",Operations=505.0 1445777612289907122
mongodb operations="D",AverageLatency(us)=1712.0039603960397 1445777612290864948
mongodb operations="E",MinLatency(us)=253.0 1445777612294065941
mongodb operations="F",Return=505 1445777612325747187
感谢。
答案 0 :(得分:3)
可能不是最漂亮的解决方案,但这应该可以解决问题
awk -F"[][, ]+" '{str=$3; sub(/Time/,"RunTime", str); \
sub(/=0/, "", str); \
if(NR>1){print "mongodb operations=\""$2"\","str"="$4,$1}}' input
在此解决方案中,前两个单词mongodb operations
是硬编码的。由于您需要的输出,必须包括两个字符串替换(时间 - > RunTime和Return = 0 - >返回)
答案 1 :(得分:2)
$ cat tst.awk
BEGIN { FS="[][[:space:],]+" }
NR>1 {
sub(/^Time/,"Run&",$3)
sub(/=[0-9]+$/,"",$3)
printf "mongodb operations=\"%s\",%s=%s %s\n",$2,$3,$4,$1
}
$ awk -f tst.awk file
mongodb operations="A",RunTime(ms)=3344.0 1445777612279125121
mongodb operations="B",Throughput(ops/sec)=299.0430622009569 1445777612288777627
mongodb operations="C",Operations=505.0 1445777612289907122
mongodb operations="D",AverageLatency(us)=1712.0039603960397 1445777612290864948
mongodb operations="E",MinLatency(us)=253.0 1445777612294065941
mongodb operations="F",Return=505 1445777612325747187