0

how to change word in text file by VB script (like sed in unix)

2
  • 1
    yael, most of your questions have been somewhat programming related, and several have been migrated to Stack Overflow. you really need to register your account here, then register a Stack Overflow account with the same OpenID; that way you'll regain ownership of the question after it migrates. this question will be migrated shortly. Commented Jun 16, 2010 at 15:57
  • 1
    please try to understand the differences between the sites, and post your future questions to the right site. Commented Jun 16, 2010 at 15:58

2 Answers 2

1

You can use the FileSystemObject Object. Some notes:

Set fs = CreateObject("Scripting.FileSystemObject")
sf = "C:\Docs\In.txt"

Set f = fs.OpenTextFile(sf, 1) ''1=for reading
s = f.ReadAll
s = Replace(s, "Bird", "Cat")
f.Close
Set f = fs.OpenTextFile(sf, 2) ''2=ForWriting
f.Write s
f.Close
Sign up to request clarification or add additional context in comments.

Comments

0

Following steps: (when tackling a computing problem, divide and conquer!)

  1. Open the text file
  2. Save file contents to string variables
  3. Close the text file!
  4. Search variable for the word
  5. Replace the word(s)
  6. Save the variable as a text file overwriting old one

With the help of Google, you should be able to search and discover how to achieve all of the above points.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.