Solved

VBscript, Sort Data, text file

Posted on 2008-10-01
8
2,288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

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…
Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

749 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