Ok, I've compiled everything above and run it on a test file and I've been having some problems. Here's the script I have:
Option Explicit
Dim dicReplacements : Set dicReplacements = CreateObject("Scripting.Dictionary")
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim oOutFile : Set oOutFile = oFSO.CreateTextFile("C:\scripts\TestOutput.txt")
Dim strLine
Dim strNewLine
Dim strNewName
For Each strLine in Split(oFSO.OpenTextFile("C:\scripts\Data-Hostnames.txt").ReadAll(), vbCrLf)
dicReplacements.Add Split(strLine, ",")(0), Split(strLine, ",")(1)
Next
For Each strLine in Split(oFSO.OpenTextFile("C:\scripts\Data-ShIntDescTest.txt").ReadAll(), vbCrLf)
For Each strNewName in dicReplacements.Keys()
strNewLine = Replace(strLine, dicReplacements(strNewName), strNewName)
If strNewLine <> strLine Then
oOutFile.WriteLine strNewLine
Exit For
End If
Next
Next
oOutFile.Close()
When I run the file one thing is as expected - it only saves the lines that have been changed to the output file. But I've tried to implement something that keeps the lines that the hostnames are on, and lines with colons. I've added these two lines to the Data-Hostnames.txt file:
hostnamekeep,hostnamekept
:,:keep:
I then used Notepad's search & replace feature to change part of my login prompt to "hostnamekeep" because that line has the hostname in it. The idea being, that when the script above runs through and makes these replacements it'll change the line and thus be caught by the If strNewLine <> strLine statement. Unfortunately this isn't working and I can't figure out why. I've tried a couple variations, no luck. Any ideas?
<message edited by emailsbecker on Tuesday, March 09, 2010 7:30 AM>