用awk取出文件内容里所需要的名字和总数
用awk取出文件内容里所记录的名字和每个名字下面的总数是多少?
# cat all.txt
[100] 15:06:03 [SUCCESS] 405b.cloud
Id Name State
----------------------------------------------------
1 i-nd105asdfjkhsfowefwefwfe run
2 i-nd105asdfjkhsfowefwefwfe run
3 i-nd105asdfjkhsfowefwefwfe run
4 i-nd105asdfjkhsfowefwefwfe run
5 i-nd105asdfjkhsfowefwefwfe run
6 i-nd105asdfjkhsfowefwefwfe run
7 i-nd105asdfjkhsfowefwefwfe run
[100] 15:06:03 [SUCCESS] 405b0.cloud
Id Name State
----------------------------------------------------
1 i-nd105asdfjkhsfowefwefwfe run
2 i-nd105asdfjkhsfowefwefwfe run
[100] 15:06:05 [SUCCESS] 405b.cloud
Id Name State
----------------------------------------------------
1 i-nd105asdfjkhsfowefwefwfe run
2 i-nd105asdfjkhsfowefwefwfe run
3 i-nd105asdfjkhsfowefwefwfe run
4 i-nd105asdfjkhsfowefwefwfe run
5 i-nd105asdfjkhsfowefwefwfe run
6 i-nd105asdfjkhsfowefwefwfe run
7 i-nd105asdfjkhsfowefwefwfe run
4 i-nd105asdfjkhsfowefwefwfe run
5 i-nd105asdfjkhsfowefwefwfe run
6 i-nd105asdfjkhsfowefwefwfe run
7 i-nd105asdfjkhsfowefwefwfe run
# awk '/SUCCESS/{b=$0;a[b]}/run/{a[b]++}END{for(i in a)print i,a[i]}' all.txt
[100] 15:06:03 [SUCCESS] 405b.cloud 7
[100] 15:06:03 [SUCCESS] 405b.cloud 2
[100] 15:06:05 [SUCCESS] 405b.cloud 11
# awk -F '[ :]+' '{print $4,$NF}' all.txt
405b.cloud 7
405b.cloud 2
405b.cloud 11
版权声明:本文为cfy930721原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。