我试图筛选日志文件,并正在到的问题,我有什么到目前为止以下,这是不行的,尾-f,AWK并输出到文件>
tail -f /var/log/squid/accesscustom.log | awk '/username/;/user-name/ {print $1; fflush("")}' | awk '!x[$0]++' > /var/log/squid/accesscustom-filtered.log
目标为获取包含
ipaddress1 username
ipaddress7
ipaddress2 user-name
ipaddress1 username
ipaddress5
ipaddress3 username
ipaddress4 user-name
一个文件并保存到accesscustom-filtered.log
ipaddress1
ipaddress2
ipaddress3
ipaddress4
其作品,未经输出访问custom-filtered.log,但>中的某些内容不能正常工作,并且文件最终为空。
编辑:改变了原来的例子是正确的
我没看到那个'awk'命令的结束单引号(''')。这是你有什么? – chrisaycock
tail -f是一个非终止命令,所以我不确定你可以通过管道将它输出到像 –
那样的文件中,你可以将它变成很时髦的东西。 – peteches