find文件并在尾部search

以下是按预期工作。

find /opt/ -name "somefile.out" -exec grep 'Connection refused' {} \; | more 

但是,如果我只想searchfind的文件的尾部,我不能像这样添加尾巴或尾巴-100 …

 find /opt/ -name "somefile.out" -exec grep 'Connection refused' tail {} \; | more 

在最后几行中search文本的最佳方法是什么?

这似乎对我有用,不知道这是否是最好的方法:

 find . -name '*.log' -exec tail {} \; | grep GET | more 

主要的是以更正确的顺序执行命令。

祝你好运!

您的问题可能已经在这里回答: https : //stackoverflow.com/questions/307015/how-do-i-include-a-pipe-in​​-my-linux-find-exec-command

你可以使用Perl的尾巴和grep的工作,但(注意:这是因为复杂性令人惊讶的复杂性,但它应该工作)半脸颊:

 find /opt/ -name "somefile.out" -exec perl -ne 'push @a, $_; @a = @a[@a-NUMBEROFLINES..$#a]; END { foreach (@a) { print if /PATTERN/ } }' '{}' \; 

如果Perl中看到某个“页脚”之后,而不是你想要扫描的一定范围的行,那么它会让你更容易:

 perl -ne 'print if /footer/ .. eof() and /PATTERN/'