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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading from a text file and adding to another.

Status
Not open for further replies.

Grunty

Technical User
Jul 30, 2002
100
GB
I have a batch file that has been run on each computer in our network to output the ipconfig command to a text file stored on each C drive.

Can anyone help me with a script that will read each ipconfig.txt file in turn, (PC's are named PC-100, PC-101 etc), extract the lines

Host Name . . . . . . . . . . . . :pC-xxx
Physical Address. . . . . . . . . :(NIC MAC Address in here)

And add them to a single text file?

Thanks
 
Set objOutput = FSO.OpenTextFile("c:\results.txt", 8, True)
For Each aComputer In colComputers
If FSO.FileExists("\\" & aComputer & "\c$\output.txt") Then
Set objTS = FSO.OpenTextFile("\\" & aComputer & "\c$\output.txt", 1, False)
Do While Not objTS.AtEndOfStream
sLine = objTS.ReadLine
Wscript.Echo sLine
objOutput.WriteLine sLine & " " & aComputer
Loop
objTS.Close
Set objTS = Nothing
End If
Next
objOutput.Close
Set objOutput = Nothing


i would have to say that i would change the process whcih creates the files on the local machine c: to actually genereate the individual files on a network share. further i would use a vbscript to generete these files using the .Exec method of WshShell to capture the stdout of ipconfig,,,or better still use something like WMI to query the ipconfig info.....
 
This is how you can do it with the output file from ipconfig /all name as input. If they locate on remote, use administrative share as mrmovie has shown to get to it.
[tt]
outfile="\\c0d1f2\\c$\output.txt" [green]'your input or from loop[/green]
[green]'watch if the file be unicode, here assumed ascii file[/green]
s=createobject("scripting.filesystemobject").opentextfile(outfile,1,true).readall

set rx=new regexp
with rx
.multiline=true
.global=true
.ignorecase=true
.pattern="(host name (\. )*: \w*)|(physical address(\. )*: ([0-9a-f]{2}-){5}[0-9a-f]{2})"
end with
set cm=rx.execute(s)
sdata=""
for i=0 to cm.count-1
sdata=sdata & cm(i) & vbcrlf
next
[green]'just to show what you get
wscript.echo sdata
'now you get what you've got, easy to save to consolidated file?[/green]
[/tt]
 
Amendment
I've got a typo there with the corresponding line read like this.
[tt]outfile="\\c0d1f2[highlight]\[/highlight]c$\output.txt" 'your input or from loop[/tt]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top