Link to home
Start Free TrialLog in
Avatar of Mike Caldwell
Mike CaldwellFlag for United States of America

asked on

Need to read a text file line by line, then write lines with a certain criteria to a save file

I have very large text files with data on a line by line basis.  I need to scan down through the file looking for a keyword that could be a trigger, then write that line out to a holding file.  When the source file reaches EOF, then close it and the target file.

I keep having the open files step on each other, and I'm not sure how to specify reading from one, then writing to the other.  Can I have both open at the same time?
Avatar of Bill Prew
Bill Prew

Can you share what you have written so far?

What is the "trigger" criteria?

What data goes into the holding file?

~bp
Avatar of Mike Caldwell

ASKER

OK, but it is very primative, and won't run due to errors.

dim filesys, filetxt
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile("G:\API Stuff\Sample Reference List.txt", ForReading, True)
set Outfile = filesys.OpenTextFile("G:\API Stuff\Sample out.txt",ForWriting)

Do until EOF
strLine = filetxt.readLine
Outfile.WriteLine = strLine
Loop

filetxt.Close
Outfile.CLose

Open in new window


The trigger is when "[Application]" is found on a line.  Then I go down a couple more lines and look for another trigger, such as "[FIELD2]", and write the line were FIELD2 was found into the out file.
Is this an INI type file by any chance?

Can you provide a sample of the input file?

~bp
stdClass Object
(
    [APPLICATION] => stdClass Object
        (
            [APNMB] => 12345678
            [PBNUM] => 20090108066
            [PBDAY] => 2009-04-30
            [PANUM] =>
            [PADAY] =>
            [EPDAY] => 2006-06-14
            [FPDAY] => 2006-03-01
            [EXPUN] =>
            [ATYPE] => Utility
            [ASTAT] => Abandoned -- Failure to Respond to an Office Action
            [NSTAT] => App Abandoned
            [STDAY] => 2012-08-27
            [EXAMN] => STANFORD, CHRISTOPHER J
            [CONFM] => 8142
            [DOCKN] => OP100000929
            [ARTUN] => 2887
            [CLASS] => 235
            [SBCLS] => 472.010
     }
}

Data like this would be repeated, perhaps hundreds of time.  I just need to first open the file, look for the first trigger, then the second trigger, say DOCKN, then copy out

      [DOCKN] => OP100000929

to the target file.
Okay, working it.  Do you want to only write out the first match in the file, or every match?

~bp
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect Bill, thanks.  I can figure out my loops, inner loops, etc, so I've got it from here.  Thanks much.
Very welcome, glad that helped.

~bp