Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a log file which I need to parse, nothing fancy, just a few thousands of lines. I need to extract specific parts of it and do some calculations. Here's an example:

ID #567
10-10-2011 Blah-blah-blah-blah
blah-blah-blah
Approx 30.65$

ID #568
11-10-2011 Blah-blah-blah-blah
blah-blah-blah
Approx 7$

The task splits in 2 parts now:

  1. I need to sum values for a given range of dates/IDs
  2. (optionally) I need to plot a graph showing X as dates and Y as values

I'm familiar with Delphi since several years now, think I could write a parser and a grid there in several hours, but I'm looking for something different.

Could you suggest me a tool that would fit for the job and not that hard to grab?

share|improve this question
Hi Krom, tools recommendation questions like this are off-topic here: if you were interested in getting help wirting that parser, that's where Programmers (for high-level help) or our sister site Stack Overflow (for help with your code) would come in. – user8 Feb 2 '12 at 9:22
You could write a small program that reads each set of 4 lines and concatenate them. Make sure you add commas and enclose text in quotes. You will end-up with a CSV file that you can load into Access, Excel, etc, and get your stats. – Emmad Kareem Feb 2 '12 at 9:24
There's no problem in writing the parser in Delphi. I was just asking if there are languages/tools specifically better for that job than Delphi. – Krom Stern Feb 2 '12 at 9:55

closed as off topic by Mark Trapp Feb 2 '12 at 9:21

Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

Microsoft provides a tool called Log Parser. It lets you parse text files, XML files as well as take data from other sources such as the Event Log, the Registry, and Active Directory. You can parse using SQL syntax as if you were coding against a database.

There even is a positive Coding Horror article about it.

As for the graph, once you have your data - for example in a CSV file - I suspect Excel would be the right tool for drawing the graph.

share|improve this answer
Unfortunately the log format is not what I can control.. – Krom Stern Feb 2 '12 at 7:54
@Kron Did you try ? This tool does not need your logs to be reformatted in a particular way. If you want to see some examples, check out logparserplus.com/Examples – Jalayn Feb 2 '12 at 8:02
Could you please expand your answer with a simple example of how could I separate one entry from the other (new entry starts when new 'ID%' is found). I got an impression that in -i:TEXTLINE all the lines are parsed separately. – Krom Stern Feb 2 '12 at 8:09
+1 for a good tool suggestion. – Emmad Kareem Feb 2 '12 at 9:10
@Krom I tried a bit but the tool does not support sub-queries unfortunately so I could get either the values or the dates, but not both at the same time... Too bad. – Jalayn Feb 2 '12 at 9:18
show 1 more comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.