从多个文件的grep搜索中获得最后一行 [英] get last line from grep search on multiple files

查看:955
本文介绍了从多个文件的grep搜索中获得最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我找到了只显示grep搜索最后一行的方法:

  grep PATERN FILE_NAME | tail -1 

我也找到了在多个选定文件中进行grep搜索的方法:

  find。 -nameFILE_NAME| xargs -I name grep PATERN name 

现在我只希望得到grep结果的最后一行为每个单个文件。
我试过这个:

  find。 -nameFILE_NAME| xargs -I名称grep PATERN名称| tail -1 

这只会返回我想要的最后一个文件的最后一个值最后匹配每个文件的模板。

解决方案

  文件名);请grep PATERN $ f |尾巴-1;完成


I'm curently having some problem with a grep command.

I've found the way to only show the last line of a grep search :

grep PATERN FILE_NAME | tail -1

I also find the way to make a grep search in multiple selected files :

find . -name "FILE_NAME" | xargs -I name grep PATERN name

Now I would like to only get the last line of the grep result for each single file. I tried this :

 find . -name "FILE_NAME" | xargs -I name grep PATERN name | tail -1

This returns me only the last value of the last file where I would like to have the last matching patern for every file.

解决方案

for f in $(find . -name "FILE_NAME"); do grep PATERN $f | tail -1; done

这篇关于从多个文件的grep搜索中获得最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆