Find largest value of integer in repeating string
Posted
by
dotancohen
on Super User
See other posts from Super User
or by dotancohen
Published on 2012-09-19T07:35:15Z
Indexed on
2012/09/19
9:41 UTC
Read the original article
Hit count: 272
I have a script log file that looks a bit like this:
2012-9-16
Did something
Did 345 things
Script time: 244 seconds
2012-9-17
Did yet something
Did another thing 23 times
Script time: 352 seconds
2012-9-18
Did something special for 34 seconds 51 times
Did nothing at all
Script time: 122 seconds
I would like to find the largest value of N
in the lines Script time: N seconds
. However, I need to keep the context, so simply removing all lines that don't contain Script time
in them is not a viable solution.
Currently, I am grepping for lines with Script time
, then sorting those to find the highest value, then going back to the original file and searching for that value. However, if there is a more straightforward way then I would love to know.
This is on Vim 7.3 on a recent CentOS. I would prefer to remain in VIM if possible. Thanks.
© Super User or respective owner