【发布时间】:2021-02-23 02:55:13
【问题描述】:
如何仅打印第 5 列中包含点 (.) 的行并删除末尾的冒号 (:)。
我想避免在 | 上重复使用 awk,而是希望用单个 awk 完成所有技巧
这是我的命令输出,awk
$ awk '{a[$5]++;} END{for(i in a) print a[i]" "i}' netappev.logs
4 wafl.vol.full:
5
3 sis.changelog.full:
1 17:58:41
1 using
1 "event
21 vifmgr.bcastDomainPartition:
4 wafl.mirror.access.denied:
76 secd.authsys.lookup.failed:
7 wafl.vol.runningOutOfInodes:
仅使用grep 打印带有点(.)的行的一种方法:
$ awk '{a[$5]++;} END{for(i in a) print a[i]" "i}' netappev.logs | grep \\.
4 wafl.vol.full:
3 sis.changelog.full:
21 vifmgr.bcastDomainPartition:
4 wafl.mirror.access.denied:
76 secd.authsys.lookup.failed:
7 wafl.vol.runningOutOfInodes:
再次使用| 和AWK 删除冒号(:)。
$ awk '{a[$5]++;} END{for(i in a) print a[i]" "i}' netappev.logs | grep \\. | awk -F: '{print $1}'
4 wafl.vol.full
3 sis.changelog.full
21 vifmgr.bcastDomainPartition
4 wafl.mirror.access.denied
76 secd.authsys.lookup.failed
7 wafl.vol.runningOutOfInodes
编辑:
@Ed Morton 在评论中询问的原始数据。
Last login time: 2/19/2021 17:58:41
Time Node Severity Event
------------------- ---------------- ------------- ---------------------------
2/19/2021 22:32:16 ksg6007 ERROR vifmgr.bcastDomainPartition: Broadcast domain KSGI_mgmt-38 is partitioned into 2 groups on node ksg6007. The different groups are: {a0a-38}, {e0M}. LIFs hosted on the ports in this broadcast domain may be at the risk of seeing connectivity issues.
2/19/2021 22:31:31 ksg6013 ERROR wafl.vol.runningOutOfInodes: The file system on Volume tpv6010_ida_ipdev_workareas@vserver:577ffe3f-4d04-11e7-92cf-00a098c5e37c is using 80 percent or more of the files that can be contained on the volume.
2/19/2021 22:30:03 ksg6005 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (28274) on Vserver (tpv6009) for client with IP address (10.137.170.142).
2/19/2021 22:29:52 ksg6007 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (45509) on Vserver (tpv6011) for client with IP address (10.137.170.112).
2/19/2021 22:29:52 ksg6014 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (45509) on Vserver (tpv6011) for client with IP address (10.137.170.112).
2/19/2021 22:28:37 ksg6006 ERROR vifmgr.bcastDomainPartition: Broadcast domain KSGI_mgmt-38 is partitioned into 2 groups on node ksg6006. The different groups are: {a0a-38}, {e0M}. LIFs hosted on the ports in this broadcast domain may be at the risk of seeing connectivity issues.
2/19/2021 22:28:01 ksg6008 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (28274) on Vserver (tpv6009) for client with IP address (10.137.170.142).
2/19/2021 22:27:15 ksg6014 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (46537) on Vserver (tpv6010) for client with IP address (10.137.171.26).
2/19/2021 22:27:00 ksg6005 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (35828) on Vserver (tpvtp605) for client with IP address (165.114.117.122).
2/19/2021 22:25:49 ksg6013 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (997) on Vserver (tpv6010) for client with IP address (165.114.118.231).
2/19/2021 22:24:49 ksg6005 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (45509) on Vserver (tpv6010) for client with IP address (10.137.170.112).
2/19/2021 22:24:49 ksg6007 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (45509) on Vserver (tpv6010) for client with IP address (10.137.170.112).
2/19/2021 22:24:49 ksg6008 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (45509) on Vserver (tpv6011) for client with IP address (10.137.170.112).
2/19/2021 22:23:49 ksg6008 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (46537) on Vserver (tpv6010) for client with IP address (10.137.171.26).
2/19/2021 22:23:49 ksg6013 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (46537) on Vserver (tpv6010) for client with IP address (10.137.171.26).
2/19/2021 22:23:47 ksg6005 ERROR vifmgr.bcastDomainPartition: Broadcast domain KSGI_mgmt-38 is partitioned into 2 groups on node ksg6005. The different groups are: {a0a-38}, {e0M}. LIFs hosted on the ports in this broadcast domain may be at the risk of seeing connectivity issues.
2/19/2021 22:23:35 ksg6008 ERROR vifmgr.bcastDomainPartition: Broadcast domain KSGI_mgmt-38 is partitioned into 2 groups on node ksg6008. The different groups are: {a0a-38}, {e0M}. LIFs hosted on the ports in this broadcast domain may be at the risk of seeing connectivity issues.
2/19/2021 22:22:37 ksg6007 ALERT wafl.vol.full: Insufficient space on volume tpv6009_scratch001@vserver:41dd0809-477f-11e7-92cf-00a098c5e37c to perform operation. 8.00KB was requested but only 1.00KB was available.
2/19/2021 22:22:35 ksg6013 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (46329) on Vserver (tpv6009) for client with IP address (165.114.116.50).
2/19/2021 22:21:12 ksg6006 ERROR wafl.mirror.access.denied: Access to SnapMirror volume 'tpv6010_da' was denied because SnapMirror initialization was not complete (exported Snapshot copy identifier '0' is invalid).
2/19/2021 22:21:04 ksg6014 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (46537) on Vserver (tpv6009) for client with IP address (165.114.118.133).
2/19/2021 22:21:02 ksg6005 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (46709) on Vserver (tpv6009) for client with IP address (10.137.169.63).
2/19/2021 22:21:02 ksg6005 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (46329) on Vserver (tpv6011) for client with IP address (10.137.170.238).
2/19/2021 22:20:58 ksg6007 ERROR vifmgr.bcastDomainPartition: Broadcast domain KSGI_mgmt-38 is partitioned into 2 groups on node ksg6007. The different groups are: {a0a-38}, {e0M}. LIFs hosted on the ports in this broadcast domain may be at the risk of seeing connectivity issues.
2/19/2021 22:20:02 ksg6005 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (46329) on Vserver (tpv6010) for client with IP address (10.137.170.238).
2/19/2021 22:19:43 ksg6013 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (46709) on Vserver (tpv6011) for client with IP address (10.137.169.63).
2/19/2021 22:19:08 ksg6013 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (994) on Vserver (tpv6011) for client with IP address (165.114.116.101).
2/19/2021 22:19:02 ksg6008 ERROR secd.authsys.lookup.failed: Unable to retrieve credentials for UNIX user with UID (45509) on Vserver (tpv6009) for client with IP address (10.137.170.112).
【问题讨论】:
-
如果您edit 您的问题包含minimal reproducible example 并具有简洁、可测试的样本输入和预期输出,那么我们可以为您提供最好的帮助。见How to Ask。
-
总是试着用积极而不是消极的方式来思考和表达你的要求,例如。而不是
remove the line which do not have dot,你可以说print only the lines which have dot。这使得需求更加清晰,避免双重否定,并避免你的需求中的否定渗透到你的代码中并使代码变得复杂。 -
@EdMorton,非常感谢您的投入,我总是遵循您的好技巧,所以我刚刚编辑了我的问题,我试图从语法上重新表述我的帖子,但我没有作为非英语母语的人,英语流利。
-
不客气。不过,我并没有要求提供原始数据,而是要求minimal reproducible example 提供简洁、可测试的样本输入和预期输出 - 您提供的原始数据并不是展示您的要求所需的最小输入集,而是预期的鉴于输入仍然缺失,因此您提供的不是minimal reproducible example 的输出。