Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Text File Writeline Script VBS

Posted on 2007-03-21
3
Medium Priority
?
1,464 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

618 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