Solved

VBscript, Sort Data, text file

Posted on 2008-10-01
8
2,224 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
 

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Today companies are subjected to more-and-more data, and it won't stop any time soon.  But there are obvious opportunities for reducing data, particularly data duplicated among companies.
Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

911 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

23 Experts available now in Live!

Get 1:1 Help Now