我正在跟踪一个日志文件,并使用grep来删除我想要的信息行,现在我想通过管道将其传递到sed中,以减少其本身的开销。
例如,原始日志为:
Feb 9 17:48:21 dnsmasq[884]: query[A] captive.g.aaplimg.com from 192.168.178.21
Feb 9 17:48:21 dnsmasq[884]: forwarded captive.g.aaplimg.com to 8.8.4.4
Feb 9 17:48:21 dnsmasq[884]: reply captive.g.aaplimg.com is 17.253.55.202
Feb 9 17:48:21 dnsmasq[884]: reply captive.g.aaplimg.com is 17.253.55.204
然后我使用grep --line-buffered " query“来获取查询行:
Feb 9 18:42:21 dnsmasq[884]: query[A] captive.g.aaplimg.com from 192.168.178.21
Feb 9 18:42:40 dnsmasq[884]: query[A] sb.scorecardresearch.com from 192.168.178.21
Feb 9 18:42:51 dnsmasq[884]: query[A] captive.g.aaplimg.com from 192.168.178.21
Feb 9 18:43:06 dnsmasq[884]: query[A] captive-cidr.origin-apple.com.akadns.net from 192.168.178.21
Feb 9 18:43:06 dnsmasq[884]: query[AAAA] captive-cidr.origin-apple.com.akadns.net from 192.168.178.21
Feb 9 18:43:21 dnsmasq[884]: query[A] time-macos.apple.com from 192.168.178.21
现在我有一个命令:
sudo tail -F /var/log/pihole.log | grep --line-buffered "query" | sed -E 's/(\query).*(\from)/\1 \2/'
因为我想把元素去掉,这样它就会变成:
18:42 captive.g.aaplimg.com
18:42 sb.scorecardresearch.com
18:42 captive.g.aaplimg.com
18:43 captive-cidr.origin.apple.com
以此类推。
我哪里错了?
发布于 2020-02-10 16:07:04
下面的命令从您描述为grep
输出的6行代码中提取所需的信息(小时、分钟以及query
和from
之间的内容,就像您在最后4行代码中描述的那样)。
sed -E 's/.*([0-9]{2}:[0-9]{2}):.*query\[[^]]*\] (.*) from .*/\1 \2/'
https://stackoverflow.com/questions/60140138
复制相似问题