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

Need Help with parsing through a Text File

Status
Not open for further replies.

roebern

IS-IT--Management
Oct 24, 2002
16
At my wits end here...
I am new to the whole VB script thing and I really need some help! I have been trying to figure out how to create a script that will read a text file that looks like the this: (only its about 20,000 Lines this is an Netware NLIST command output)
The problem is the text output is very messy in the fact that some users do not have the same number of attributes as others for example:

User: XXXUSER
Name: Name T. Name

is differant than:

User: SOMEUSER
Name: Some User
Full Name: Some E. User

is differant than:

User: USERNAME
Name: USERNAME
Home Directory:
Volume Name: ServerS1
Path: HOME2\XXXXXX
Name Space Type: DOS
Full Name: User T. Name
NGW: File ID: 8h2
NGW: Post Office: POXXXX
NGW: Account ID: My Account Id

Basically I am trying to get everything on the same line and written to another text file
for example:

test.txt
User: XXXUSER, Name: Name T. Name
User: SOMEUSER, Name: Some User, Full Name: Some E. User
User: USERNAME, Name: USERNAME, Home Directory:, _
Volume Name: ServerS1, Path: HOME2\XXXXXX, _
Name Space Type: DOS, Full Name: User T. Name, _
NGW: File ID: 8h2, NGW: Post Office: POXXXX, _
NGW: Account ID: My Account Id


I figured out how to at least get the user: username lines parsed out and into another file with the inStr function which was a major accomplishment for me but I kinda feel like I was barking up the wrong tree...
If anybody out there has any suggestions or ideas on how to better accomplish this any tips or a point in the right direction would be much appreciated...

Thanks
Nathan
 
You can try something like this:
Code:
Set fso=CreateObject("Scripting.FileSystemObject")
Set f1=fso.OpenTextFile("\path\to\nlist.txt",1)
Set f2=fso.OpenTextFile("\path\to\test.txt",2)
out=""
While Not f1.AtEndOfStream
  buf=f1.ReadLine
  If Len(Trim(buf))>0 Then
    If Left(buf,1)>" " Then
      If Len(out)>0 Then f2.WriteLine out
      out=Trim(buf)
    Else
      out=out & ", " & Trim(buf)
    End If
  End If
Wend
If Len(out)>0 Then f2.WriteLine out
f2.Close
f1.Close

Hope This Help
PH.
 
Thanks! thats exactly what I was looking to do...
Now I just need to figure out how it works.

Thanks Again for your help!!
Nathan
 
Closing IE window. Is there any way to close an IE window after running an application from within the window apart from using Sendkeys.

I would like to somehow check whether the app is still running before closing the window, as the time varies due to differing network bandwidths.
 
Romans58, It would be better to start a new thread instead hijack this one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top