一个grep'd字符串后得到的文件的一切 [英] Get everything in a file after a grep'd string

查看:445
本文介绍了一个grep'd字符串后得到的文件的一切的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天的情况想出了如果有人需要我来分离出文件的尾部,指定为一切特定字符串后(为了便于讨论,FOO)。我需要做的这立刻让用了,我知道会工作,并不予理会这样或那样的最佳途径的选项,并有以下去:

 的grep -n FOO FILE.TXT |切-f1 -d:| xargs的-I {}尾-n + {} FILE.TXT> NEWFILE.TXT

这是窃听我关于这个事情是一个单值使用的xargs。我以为我可以去挠这个我的谷歌赋但有兴趣看看有什么事情样的人出SO-地想出了这种情况。


解决方案

  SED -n'/ RE /,$ P'文件

就是发生在我右了。

Yesterday a situation came up where someone needed me to separate out the tail end of a file, specified as being everything after a particular string (for sake of argument, "FOO"). I needed to do this immediately so went with the option that I knew would work and disregarded The Right Way or The Best Way, and went with the following:

grep -n FOO FILE.TXT | cut -f1 -d":" | xargs -I{} tail -n +{} FILE.TXT > NEWFILE.TXT

The thing that bugged me about this was the use of xargs for a singleton value. I thought that I could go flex my Google-Fu on this but was interested to see what sort of things people out in SO-land came up with for this situation

解决方案

sed -n '/re/,$p' file

is what occurs to me right off.

这篇关于一个grep'd字符串后得到的文件的一切的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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