Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need IP's in text file modified.

Status
Not open for further replies.

vajpowb

Technical User
Jan 18, 2008
16
US
I need a script that takes a list of IP's in a text file and drops the last octet and rewrites back to file. Looked at Scripting Guy and have tried various times but no luck. Any help?

Thx.
 
Post what you have tried with a description of how it is deficient.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Documents and Settings\anpowell\Desktop\IP_Modify_JH\IP_List.txt", ForReading)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If Len(strLine) = 14 then
strLine = Left(strLine, 10)
strContents = strContents & strLine & vbCrLf
Else If Len(strLine) = 13 then
strLine = Left(strLine, 9)
strContents = strContents & strLine & vbCrLf
Else If Len(strLine) = 12 then
strLine = Left(strLine, 8)
strContents = strContents & strLine & vbCrLf

End If
Loop

objFile.Close

Set objFile = objFSO.OpenTextFile("C:\Documents and Settings\anpowell\Desktop\IP_Modify_JH\IP_List.txt", ForWriting)
objFile.Write strContents

objFile.Close
 
What about this ?
Code:
Const ForReading = 1
Const ForWriting = 2
Const cFile = "C:\Documents and Settings\anpowell\Desktop\IP_Modify_JH\IP_List.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(cFile, ForReading)
Do Until objFile.AtEndOfStream
   strLine = objFile.ReadLine
   strContents = strContents & Left(strLine, InStrRev(strLine,".")-1) & vbCrLf
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile(cFile, ForWriting)
objFile.Write strContents
objFile.Close

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top