如何获得行号后面的所有行 [英] How to get all lines after a line number
本文介绍了如何获得行号后面的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的文件:
string log 1
string log 2
string match
string log 4
string match
string log 5
string log 6
我需要得到最后一个字符串匹配后的所有行。我怎样才能做到这在bash?
I need to get all the lines after the last string match. How can I do it in bash?
推荐答案
首先,找到最后的字符串匹配:
First, find the last string match:
line=$(grep -n 'string match' myFile | cut -d: -f1 | tail -1)
然后,打印所有行到去年字符串匹配:
Then, print all lines up to that last string match:
sed -n "1,${line}p" myFile
如果你需要的最后一场比赛后,所有行:
If you need all lines after last match:
sed -n "$((line+1))"',$p' myFile
这篇关于如何获得行号后面的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文