Jump to content
Sign in to follow this  
Breeze

Need some assistance - Stumped

Recommended Posts

I have recently discovered Autoit and I am falling in LOVE with it! I have already used it to fix several annoying situations and at least 2 major issues. I see more on the horizon.... BUT I am having a problem with a parser that I am working on.

I wrote a quick parser to pick some data out of a large file a week or so ago, and it worked VERY well. But I specified the path and file name for the input and output files.

I decided to make this more flexible and not to hard code in the path and filenames, since they could change. I would allow the user to input those items, along with the data that they needed to parse out of the file.

I have NOT been able to get that to work! It seems to parse the same line in the file repeatedly and the output file does not get any data added to it.

I have tried putting a counter in the loop and having it pop a MSGBOX, to ensure that it is looping (it is) but it does not find the data.

I worked on this for over an hour last night adding breakpoints and looking for the problem, but I just don't see it.

COLOR=orange] In the Code below that is commented out, I attempted to make the changes, the uncommented parts worked when hard coded

;Try to quickly parse log files....
; Here goes Nothing!



;$Input = InputBox ("Path & Filename input", "Please enter the full path and filename to parse")
;$Output = InputBox ("Path & Filename output" , "Please enter the full path and filename for output")
;$Seeker = InputBox ("Parse for what string?", "Please enter the string that you want to look for...")
$begin = TimerInit ();Start a timer for later
;FileOpen ($Input,0)
;FileOpen ($Output,1)
$Input = FileOpen ("C:\CC Log Files\trans.log",0);
$Output = FileOpen ("C:\CC Log Files\PTrans.txt",1)


while 1
    $line = FileReadLine($Input)
    If @error = -1 Then ExitLoop
        If StringInStr ($line, "HL7Parser") Then  
            ;If StringInStr ($line, $Seeker) Then
        $len = Stringlen ($line)
            If $len > 42 Then 
            $line = StringRight ($line, 42)
            EndIf
    FileWrite($Output, $line & @CRLF)
        EndIf
Wend
    
FileClose ($Input)
FileClose ($Output)
$runtime = TimerDiff ($begin)
$runtime = ($runtime / 1000)
MsgBox (0, "Run Time", "Seconds to Complete Parsing log file:"  & $runtime ,12)

The Hard coded version worked VERY well. I was able to parse all of the needed data out of a 71MB Log File into the output file in under 5 Minutes! a BIG improvement over the attempt to use a Word Macro... that had not even completed when left to run overnight!

TIA for any assistance

Breeze

Edited by Breeze

Share this post


Link to post
Share on other sites

Not really sure why you're trying to parse 'C:\CC Log Files\trans.log'. Why not just accept input like that? Or use a FileOpenDialog? :)

Also, look into _FileReadToArray, I think it may make parsing your files many times faster.

EDIT:

This post sorta relates to yours:

http://www.autoitscript.com/forum/index.ph...wtopic=9809&hl=

Edited by Insolence

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
Share on other sites

This will only write the lines with "HL7Parser" in it. Is it many?

<{POST_SNAPBACK}>

It CAN be a lot. I edited the code just a bit before posting to protect the source of the facility I captured the log files from, but the target log files are from Hospital HL7 interfaces. These logs capture all of the data that flows to and from a system in a day, then the log is given a fixed name and rolled over every 7 days. Prior to this, no parser existed to allow detailed examination of the log file, with this I could pull the date and time stamp data out of the file and determine the latency of the HL7Parser, which inserts its name and a date time stamp on each processed line.

The Target log files on this system were as large as 500MB+

When hard coded, it really worked sweet! I just thought I would open it up a bit (HL7Parser could change to be something else, it can be site specific). This would allow others to enjoy the benefits of my brilliant coding efforts :) They could run an EXE and it would ask them what they wanted to look for.

Breeze

Share this post


Link to post
Share on other sites

Not really sure why you're trying to parse 'C:\CC Log Files\trans.log'.  Why not just accept input like that?  Or use a FileOpenDialog:)

Also, look into _FileReadToArray, I think it may make parsing your files many times faster.

EDIT:

This post sorta relates to yours:

http://www.autoitscript.com/forum/index.ph...wtopic=9809&hl=

<{POST_SNAPBACK}>

Insolence,

Thanks for the quick reply!

I am not really trying to Parse the file path, I am asking the user to enter the file path and name, and the output file path and name, then asking WHAT they want to look for in the input file.

I am still really new to Autoit, I used to do a bit of BASIC programming... a LONG time ago. I used arrays then, but I have not checked into them in Autoit. Based upon the link you supplied, it looks like that might be a speed enhancer....

Thanks,

Breeze

Share this post


Link to post
Share on other sites

Is FileOpenDialog a solution to your problem? An InputBox as to what they want to search for should work.


"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
Share on other sites

Is FileOpenDialog a solution to your problem?  An InputBox as to what they want to search for should work.

<{POST_SNAPBACK}>

It SEEMS to me that the problem is with the StrInStr Function. I am attempting to allow it to seek the CONTENTS of $Seeker. When I hard code it to HL7Parser, it works, when I use the variable, it does not work.... I have tried every permutation of it I can think of.

Breeze

Edited by Breeze

Share this post


Link to post
Share on other sites

I would be checking the file size before using _FileReadToArray. 500Mb+ files are very big. You would need alot of memory to cope with this. FileGetSize() may help with adding a cut-off point, on size, so the script could abort or use an alternative method for files that are huge, like the one script above. Depending on the computer system being used.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...