Solved

Text File Writeline Script VBS

Posted on 2007-03-21
3
1,387 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
  • 2
3 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 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

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 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

11 Experts available now in Live!

Get 1:1 Help Now