?
Solved

Text File Writeline Script VBS

Posted on 2007-03-21
3
Medium Priority
?
1,448 Views
Last Modified: 2008-01-09
I Have a SVCBRIPT that reads a file and then writes to another file with some changes. However i can figure out how to do the last two things. I need it to strip everything from the line after "/". I also want to then delete the lines that may contain two of the same address.

The Format of List1.txt is below

http://137.122.144.15/
http://137.99.27.45/simulations/
http://139.130.137.16/genecom98/
http://139.130.239.70/

The format of List2.txt is below

gatekeeper.dec.com/pub/data/shakespeare
index.html
intranet.vca.unimelb.edu.au/research
io.cc.gettysburg.edu
laog.obs.ujf-grenoble.fr/pub/publications/letter_denis

The Script i used to do this is below.
Set FileSys = CreateObject("Scripting.FileSystemObject")
Set EduFile = FileSys.OpenTextFile("List1.txt", 1)
Set ISAFile = FileSys.CreateTextFile("List2.txt",True)

Dim RawDomainString

Do While EduFile.AtEndofStream <> True
RawDomainString = EduFile.ReadLine

wscript.echo CheckString(RawDomainString)

ISAFile.writeline CheckString(RawDomainString)
Loop

ISAFile.close
EduFile.Close

Function CheckString(Raw)

'Check the string to remove any http:// or ftp:// from the start of the line, and any / from end of line
Raw = LCase(Raw)

If InStr(Raw, "http://www.") then
Raw = Replace(Raw, "http://www.", "")
End If

If InStr(Raw, "gopher://") then
Raw = Replace(Raw, "gopher://", "")
End If

If InStr(Raw, "ftp://") then
Raw = Replace(Raw, "ftp://", "")
End If

If Right(Raw,1) = "/" then
Raw = Left(Raw,(Len(Raw)-1))
End If

CheckString = Raw

End Function
0
Comment
Question by:dion_p1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 18762981
Try this...

Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile: Set objFile = objFSO.OpenTextFile("C:\Testing\myfile.txt")
Dim dicSort: Set dicSort = CreateObject("Scripting.Dictionary")
Dim RawDomainString

Do While Not objFile.AtEndofStream
  On Error Resume Next
  RawDomainString = CheckString(objFile.ReadLine)
  dicSort.Add RawDomainString, dicSort.Count
Loop

objFile.Close
Set objFile = objFSO.CreateTextFile("C:\Testing\myfile.txt")
For Each Item In dicSort
  objFile.writeline Item
Next
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing

Function CheckString(Raw)
'Removes any leading http, gopher, ftp from the string and returns lcase version
Raw = LCase(Replace(Replace(Replace(Raw, "http://", ""), "gopher://", ""), "ftp://", ""))

CheckString = Left(Raw, InStr(Raw, "/") - 1) 'strips everything from the last / over
End Function
 

0
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 18763029

1/ the format of List1.txt doesnt lead to List2.txt !

where does gatekeeper.dec.com/pub/data/shakespeare come from ?

2/ is the first line of List1.txt actually.... ?
http://137.122.144.15/gatekeeper.dec.com/pub/data/shakespeare or is the script to do a DNS lookup ?

We need a matching part of test1 and what you want test2 to look like.


3/ the duplicate lines is already answered in other q. very elegantly.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18791622
Happy to help - thanx for the grade! :^)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

770 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