如何在多个文件的尾部使用 grep

如何在多个文件的尾部使用 grep

我需要 tail 几个文件,其中大部分信息我都删除了(使用 grep)。现在我的输出被文件名弄脏了。我该如何删除它们?

问题简述: $ tail -F /log/rest_server*.log | egrep -v ' INFO (<some regext>)'

返回:

==> /log/rest_server_dbs0.log <==

==> /log/rest_server_dbs1.log <==
<some useful data1>

==> /log/rest_server_dbs0.log <==

==> /log/rest_server_dbs1.log <==
<some useful data2>

==> /log/rest_server_dbs0.log <==

==> /log/rest_server_dbs1.log <==

==> /log/rest_server_dbs0.log <==

==> /log/rest_server_dbs1.log <==

==> /log/rest_server_dbm0.log <==
<some useful data3>

==> /log/rest_server_dbs1.log <==

==> /log/rest_server_dbs0.log <==

==> /log/rest_server_dbs1.log <==

==> /log/rest_server_dbs0.log <==

==> /log/rest_server_dbs1.log <==

==> /log/rest_server_dbs0.log <==

==> /log/rest_server_dbs1.log <==

==> /log/rest_server_dbm0.log <==
<some useful data4>

==> /log/rest_server_dbs1.log <==

如果没有数据,我该如何删除这些文件名和黑线?

取得成果

==> /log/rest_server_dbs1.log <==
<some useful data1>
<some useful data2>

==> /log/rest_server_dbm0.log <==
<some useful data3>
<some useful data4>

答案1

您可以改用以下命令:

$ tail -F /log/rest_server*.log | sed -e "/^==>/d;/^$/d" | egrep -v ' INFO (<some regext>)'

sed 命令删除以“==>”开头的行和空行;

相关内容