1.

Solve : Need to simplify searching HUGE logs?

Answer»

I’m looking for a WAY to search a huge log file for a string but I need the output to show me something like the 10 lines before or after the string. We have an application that generates HUGE logs. I can grep the logs for a text string but the output doesn’t show me everything I need to see. So, once determining the string is present I have to go into the log and go from {pattern} to {patern}, sometimes all the log entries for an event can be spread over hundreds of lines, with other events mixed in, depends on when the other interfaces respond. Hundreds of lines cover only a couple seconds.

I’ve tried multiple and assorted combinations of “cat”, ‘”sed” etc etc. So, far I’m clueless.

Is there some way to search a log for a specific string and have the output include lines above and or below the string?
So something like clicking cache on google and getting your search highlighted and you can see it in context? If you look through google I think there is a way to use their software to do something like that.you can try as below:
grep -B1 "your search text" yourtextfilenamehere | grep -v ^\-\- > result.txtThanks for your contribution, Mylove52, but this topic is over 4 years old. Oh, is that so Co2 :-)

COULD you please tell us then what would be the solution.Many Thanks.Personally, I haven't used Linux much at all, so I'm not sure as to what the solution is. However, I don't think Mike Mowry would mind.There are so many ways to do this, It would help if the TS would outline a method that he thinks would work. Then different ones here might give code in various scripts or program languages. The issue is a piratical method, not which language.
Like this:
Code: [Select]SPECIFY Log File
Specify target string
Name output
Number of lines to induce before and afte
Read until end of log file
Find target string
write lines before
write target line
write lines after
end

the solution is as posted
Code: [Select]grep -A10 -B10 "search string" file
I think CARBONS point was that posting a solution is a complete waste of time on account of the age of the thread. additionally the topic starter is "no longer with us" so to speak.i don't really think it matters, no solution is posted in the first place. It might benefit those who are searching the forums for similar posts. I do agree that if a solution is already posted, then bumping up this thread is unnecessary (unless it offers new insights to possible solutions)The POST was from four years back.
So, I just amused he was from
Alpha Centauri



Discussion

No Comment Found