Re: Help on reading a file and producing another in vbs by tom
tom
Mon Dec 26 12:15:40 CST 2005
Thanks James, it's perfect. I don't program in vbs, but needed
something for a WIndows environment. I know Unix. I tried downloading
a couple of my Unix commands and massage the data with no luck. I see
what you did here and was able to add further modifications. Thanks
you and Happy News Years!!
[snip]
On Mon, 26 Dec 2005 10:13:21 -0600, "James Whitlow"
<jwhitlow@letter.com> wrote:
>"tom" <tom@hotmail.com> wrote in message
>news:8kdvq1904ubggifth8aku9qt6v1mui9rf6@4ax.com...
>> I would like to write a vbscript that reads the below file:
>>
>> FILENAME: raw_data.txt (for example)
>> one
>> two
>> three
>> four
>> five
>> six
>>
>> ..... and produce the following under FILENAME: data.txt
>> [01]
>> title=one
>> chain= "Link", "one"
>> [02]
>> title=two
>> chain= "Link", "two"
>> [03]
>> title=three
>> chain= "Link", "three"
>> [04]
>> title=four
>> chain= "Link", "four"
>> [05]
>> title=five
>> chain= "Link", "five"
>> [06]
>> title=six
>> chain= "Link", "six"
>>
>> The numbering in the brackets has to be incremented. The actual raw
>> data will be about 4000 rows, the above is an example. Thanks for any
>> help!
>
> See if this does what you want:
>
>'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>Dim oFSO, oFile, oLine, sInpFile, sOutFile, x
>Dim sInpFileName, sOutFileName
>
>sInpFileName = "raw_data.txt"
>sOutFileName = "data.txt"
>
>Set oFSO = CreateObject("Scripting.FileSystemObject")
>
>Set oInpFile = oFSO.OpenTextFile(sInpFileName, 1)
>Set oOutFile = oFSO.OpenTextFile(sOutFileName, 2, True)
>
>x = 0
>
>Do Until oInpFile.AtEndOfStream
> oLine = oInpFile.ReadLine
> If Len(oLine) Then
> x = x + 1
> oOutFile.Writeline "[" & x & "]"
> oOutFile.Writeline """Link"", """ & oLine & """"
> oOutFile.Writeline "chain= ""Link"", """ & oLine & """"
> End If
>Loop
>
>oInpFile.Close
>oOutFile.Close
>'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> The only real difference between the output of this script and the
>requested output is that the incremental numbers in the brackets do not have
>a preceding zero. This is easy enough to do, but since you mentioned that
>you will have about 4000 rows, would you only want the preceding zeros for 2
>digit numbers or would you want all numbers to be the same length? If the
>latter is true, we would want to put 3 zeros in front of the single digit
>numbers.
>