Solved

Text File Writeline Script VBS

Posted on 2007-03-21
3
1,370 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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