Solved

VBscript, Sort Data, text file

Posted on 2008-10-01
8
2,245 Views
Last Modified: 2013-12-17
I have a list of data in a text file I want to sort in a specific format.
From this:
0101080030
0101080031
0101080032
0101080033
0101080034
0101080035
0101080040
0101080041
0101080042
0101080043
0101080044
0101080045
0101080050
0101080051
0101080052

To this:
0101080010,0101080011,0101080012,0101080013,0101080014,0101080015
0101080020,0101080021,0101080022,0101080023,0101080024,0101080025

The idea is to read each line, if the number ends in a '0' start a new line to a new text file in comma delimited format until you get another number that ends in a '0' then start a new line.

Any assistance appreciated.
0
Comment
Question by:TekNoxious
  • 3
  • 3
  • 2
8 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 22622647
Hmm. In JS it would be
str.replace(/\n/g,',').replace(/0,/g,'0\n')
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22623365
This should do it..

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
arrData = Split(objFSO.OpenTextFile("C:\Source.txt").ReadAll, vbNewLine)
Set objOutput = objFSO.CreateTextFile("C:\NewOutput.txt") 
x = 0
For Each strData in arrData
  x = x +1
  If x 6 7 Then
    objOutput.Write strData & ","
  Else 
    x = 0
    objOutput.WriteLine  strData
  End
Next 
objOutput.Close

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 22623491
what does

  If x 6 7 Then


mean???

Where is the test for the last digit being 0?
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:TekNoxious
ID: 22625695
I am with mplungjan about that line and missing function.
I would accept Jscript if that would make this an easier task. I am welcome to learning something new.
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 300 total points
ID: 22625910
Sorry - my rushed attempt before heading out the door...
This should work for you:
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFSO.OpenTextFile("F:\Test.txt")
Dim objOutput : Set objOutput = objFSO.CreateTextFile("F:\New.txt")
 
Do While Not objFile.AtEndOfStream
  If strTemp = "" Then strTemp = objFile.ReadLine
    If Right(strTemp, 1) = "0" Then
      WriteLine strData
       strData = ""
      strData = strData & strTemp & ","
    Else
      strData = strData & strTemp & "," 
    End If
    strTemp = ""
Loop
 
WriteLine strData
 
objoutput.Close
 
Sub WriteLine (strData)
  If strData = "" Then Exit Sub
  End If
  objOutput.WriteLine Left(strData, Len(strData) -1)
End Sub

Open in new window

0
 

Author Comment

by:TekNoxious
ID: 22626534
The 'End If' needed to be removed from the Sub then it worked!
Thank you for the VBscript lesson.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22626557
accidental delete...originally
  If strData = "" Then
    Exit Sub
  End If

0
 

Author Closing Comment

by:TekNoxious
ID: 31502177
Thank you for your time and support.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

816 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

10 Experts available now in Live!

Get 1:1 Help Now