[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1488
  • Last Modified:

Text File Writeline Script VBS

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
dion_p1
Asked:
dion_p1
  • 2
1 Solution
 
sirbountyCommented:
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
 
Robberbaron (robr)Commented:

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
 
sirbountyCommented:
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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now