PDA

View Full Version : Log file data extraction



gabepari
01-20-2009, 05:35 PM
Hey all you coders out there. What is the easiest way to extract data from a text file? I think I could do it in excel, but haven't really played with it yet.

What I want is to be able to point to a *.log file and have it pull out the Elapsed times for all the complete file runs and total them. There's alot more I would like (maybe a 50 pound bag of $5 bills
), but if I can make that work, then I can modify and add features later.

I haven't played with Apple script much, but maybe I could use that??

Thanks,

Gabe Pari
www.socalteardrops.com (http://www.socalteardrops.com)

carlosgmarroquin
01-20-2009, 07:12 PM
With excel you can load data if it's structured like records (each line) and fields within each line. Each field will go to a different cell in the worksheet. Excel recognizes data separated by some delimiter like comma or pipe (|) and also recognizes fixed length fields.

You just have to open the file in excel and a wizard will pop up.

I imagine that a log file doesn't have the ideal format to load in excel. If you use Unix you can write a text processing script using awk.

Hope it helps.

Carlos

carlosgmarroquin
01-20-2009, 07:21 PM
Another thought.

In Excel you can load the whole lines. And with a macro in VBA inside the Excel file you could scan each line looking for a pattern that you know contains the data you want to extract. The macro's output could be another woorksheet with the processed usable data.

dana_swift
01-21-2009, 08:25 AM
In C# I use:

using System.IO;

*******

string[] FileContents = File.ReadAllLines("C:\ ... logpath to file.log");

foreach(string Line in FileContents)
{
string []Fields = Line.Split(',');

... now do something with the data in each record
}

******

Those 5 lines of code get used a lot!

D

Gary Campbell
01-21-2009, 01:04 PM
Dana...
You make that post as though someone from planet earth could understand it!

Gary

dana_swift
01-21-2009, 02:17 PM
Gary, last time I checked I was from planet earth! You are too, and could read it and modify it if you wanted to..

I like code that is readable, even if it isn't obvious as to how to write it.

D

sepdx
08-19-2014, 06:02 PM
There is a Shopbot Labs project that might help, though it's a bit of a shotgun approach:

http://www.shopbottools.com/LabFiles/odometer.htm

It pops open a window that shows every job ever run sorted/separated by date; it will kick out a .csv file that imports into Excel much easier than the typical Shopbot .log file. The field headings at the top were a bit off in Excel, but easy to fix...or ignore and simply use to populate a more useful worksheet.

donek
08-19-2014, 11:27 PM
1. Open Log File in excel
2. select the delimited radio button
3. Click next
4. check space under delimeters
5. click finish
6. select all columns
7. under data tab select sort
8. sort by column E (column containing "Elapsed" and "Max")
9. click OK
10. Elapsed data is now in Column F
Sum or manipulate as you like.

ssflyer
08-20-2014, 12:22 AM
Hey Dana,

Great post - perfectly understandable. And yes, those 5 lines do get used a lot!

adrianm
08-20-2014, 03:50 AM
This is a five year old thread. I expect Gabe has it sorted by now. ;)