Solved

Script to create import file

Posted on 2013-05-24
2
290 Views
Last Modified: 2013-05-24
I need a script that will read a text file, and for every line in the text file create a few lines of data in a second text file.

input text file looks like this
navs.org.ukhome
negotiationisdone.com
negotiationisdone.wordpress.com
negotiationisover.blogspot.com
negotiationisover.com

I need the out put file to look like this

               edit "navs.org.ukhome"
                    set action block
                    set type wildcard
                next
                edit "negotiationisdone.com"
                    set action block
                    set type wildcard
                next
            edit "negotiationisdone.wordpress.com"
                    set action block
                    set type wildcard
                next
            edit "negotiationisover.blogspot.com"
                    set action block
                    set type wildcard
                next
            edit "negotiationisover.com"
                    set action block
                    set type wildcard
                next
0
Comment
Question by:TheonW
2 Comments
 
LVL 15

Accepted Solution

by:
ZabagaR earned 500 total points
ID: 39195470
This works, I just tried it:

The variable strFileName will be your final OUTPUT file
The file I called c:\servers.txt would contain the list of your .com web sites.
------------------------------------------------------------------------------------------------------------------------------


Const FOR_APPENDING = 8
strFileName = "C:\testfile.txt"
Const ForReading = 1

Set objFS = CreateObject("Scripting.FileSystemObject")
Set MyFile = objFS.CreateTextFile(strFileName, True)
MyFile.Close
Set objTS = objFS.OpenTextFile(strFileName,FOR_APPENDING)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\servers.txt", ForReading)

Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    arrServiceList = Split(strNextLine , ",")

objTS.Write "edit " & Chr(34) & arrServiceList(0) & Chr(34) & vbCrLf
objTS.Write "set action block" & vbCrLf
objTS.Write "set type wildcard" & vbCrLf
objTS.Write "next" & vbCrLf

Loop
ObjTS.Close
0
 
LVL 3

Author Closing Comment

by:TheonW
ID: 39195635
I made a few changes for spacing and notice that you put the create file first, no big deal,  easy fix, thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now