/build/static/layout/Breadcrumb_cap_w.png

vbscript to append content to specific line of text

Hello

can any one please post a vbscript to append the content to a specific line (Say line 5) of a text and also vbscript for deleting the content
Thanks in advance.

0 Comments   [ + ] Show comments

Answers (2)

Posted by: murali.bhat 13 years ago
Purple Belt
0
Read the text file lines one by one. When you get the string which you are searching for, add your string to it. Store this in another string and write back to the text file.

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("<PATH TO YOUR FILE>") then
Set objFile = objFSO.OpenTextFile("<PATH TO YOUR FILE>", 1)

Do Until objFile.AtEndOfStream
strLine = objTextFile.Readline
If strNextLine = "LINE YOU ARE LOOKING FOR" then
strLine = strLine + " ADD YOUR STRING HERE"
End If

strNewText = strLine + vbcrlf
Loop
Set objFile = Nothing

Set objFile = objFSO.OpenTextFile("<PATH TO YOUR FILE>", 2)
objFile.Write strNewText
Set objFile = Nothing
End If
Posted by: anonymous_9363 13 years ago
Red Belt
0
It's much more efficient to use ReadAll, then Split using vbCRLF as the delimiter to create an array, then loop through the array.

For deleting a line, you simply hop over it in the testing loop.

BTW, if - as I suspect - you're appending to the HOSTS or SERVICES file, remember to test whether or not the data you're adding is already present.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ