Copy sections of one text file to another text file.
-
Friday, February 01, 2013 3:02 PM
I’m new to vbscripting and powershell, but I need to read a text file and copy sections out to another text file. Is this possible?
I need to read the first text file line by line until I come to a specific word, (like ‘keyword’) then from that point on copy each line read to another text file until I come to another set of words. (like ‘this’ or ‘that’) then go back to reading the text file until I come to the first ‘keyword’ again and start copying line to the second text file again, until I come to ‘this’ or ‘that’.
Can someone help me with this?
All Replies
-
Friday, February 01, 2013 3:12 PMModerator
Hi,
What you're asking is possible and is doable in both VBScript and PowerShell. A PowerShell solution will be shorter than equivalent VBScript code.
The purpose of this forum is to get help with scripting questions; we generally don't have the resources to write scripts on demand. (This would amount to free consulting work.) If you have an existing script that you're having problems with, feel free to post it and also post any error message(s) you are getting.
Bill
-
Friday, February 01, 2013 3:19 PMLike I said I'm new to scripting, so if powershell would be a shorter solution, let me do some research and see if I can come up with something. Without having to learn powershell first, I'm in a crunch to get this done as soon as possible, would you be able to recommend a web site to start my search.
-
Friday, February 01, 2013 3:20 PMModerator
- Proposed As Answer by Bill_StewartMicrosoft Community Contributor, Moderator Wednesday, February 06, 2013 10:59 PM
- Marked As Answer by Bill_StewartMicrosoft Community Contributor, Moderator Monday, February 11, 2013 9:30 PM
-
Friday, February 01, 2013 3:21 PM
Here is the pseudo-code VBScript version of what you're trying to do:
- Open the first text file.
- Read all lines into an array.
- Close the first text file.
- Open the second text file.
- Move down in the array until you find the keyword. Memorise the record number R1.
- Move down in the array until you find "this". Memorise the record number R2.
- Write all records from R1 to R2 to the second text file.
- Repeat steps 5 to 7.
- Close the second text file.
It's actually a typical coding example for a VBScript beginner's class.
- Proposed As Answer by Bill_StewartMicrosoft Community Contributor, Moderator Wednesday, February 06, 2013 10:59 PM
- Marked As Answer by Bill_StewartMicrosoft Community Contributor, Moderator Monday, February 11, 2013 9:31 PM

