Mike Caldwell
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?
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?
ASKER
OK, but it is very primative, and won't run due to errors.
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.
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
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
Can you provide a sample of the input file?
~bp
ASKER
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.
(
[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
~bp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
~bp
What is the "trigger" criteria?
What data goes into the holding file?
~bp