Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Replace text in file between known text?

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,61724
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Replace text in file between known text?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Replace text in file between known text? - 6/23/2008 1:17:42 AM   
  Derp

 

Posts: 16
Score: 0
Joined: 1/16/2007
Status: offline
Anyone have a template or some code where I can do a find and replace on some text in a file?

Lets say I have a file, NewStuff.txt, and inside there, I have this:

#### Start this is new ####
Everything here=1
Is what I need=server.com
#### End this is new ####

I have a file that has the same text in it called Computer.txt:

#### Start this is new ####
This is different=1
I need to change=this.com
#### End this is new ####

I need to open Computer.txt and replace whatever is inbetween #### Start this is new #### and #### End this is new #### with whatever is inbetween NewStuff.txt's comments.  I know how to do the basics, open file, write to it, save it, and even have a basic find and replace.. but, how do I remove all text inbetween 2 lines of code without knowing how many lines there will be?
 
 
Post #: 1
 
 RE: Replace text in file between known text? - 6/24/2008 2:39:09 AM   
  Derp

 

Posts: 16
Score: 0
Joined: 1/16/2007
Status: offline
so, nobody knows?

(in reply to Derp)
 
 
Post #: 2
 
 RE: Replace text in file between known text? - 6/24/2008 2:42:01 AM   
  ebgreen


Posts: 5041
Score: 31
Joined: 7/12/2005
Status: offline
You didn't ask if anyone knows how to do this. You asked for code. I don't have the code laying around to do exactly what you want. I do know how to write that code. So what exactly are you asking for?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Derp)
 
 
Post #: 3
 
 RE: Replace text in file between known text? - 6/24/2008 11:49:43 PM   
  Derp

 

Posts: 16
Score: 0
Joined: 1/16/2007
Status: offline
My apologies!  I'm looking for any help to do something like this.  Code, snippets, pointing me to a method or function, etc.  I know VB enough to get around, but haven't had to do anything like this before.  I'd assume I'd have to use some sort of pattern matching?

(in reply to Derp)
 
 
Post #: 4
 
 RE: Replace text in file between known text? - 6/25/2008 12:28:27 AM   
  ebgreen


Posts: 5041
Score: 31
Joined: 7/12/2005
Status: offline
So, to open a file and work with it search the forum for these terms:

FileSystemObject
.OpenFile
.ReadLine
.ReadAll

For the replacement there are several options and you will have to decide how you want to do it. These terms will help you get started:

Replace
InStr
Regular Expression
Regexp

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Derp)
 
 
Post #: 5
 
 RE: Replace text in file between known text? - 6/25/2008 2:54:32 AM   
  Derp

 

Posts: 16
Score: 0
Joined: 1/16/2007
Status: offline
found what i was looking for:

http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct07/hey1023.mspx

(in reply to Derp)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Replace text in file between known text? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts