Computer Hope

Microsoft => Microsoft DOS => Topic started by: poenie on August 17, 2007, 11:00:52 PM

Title: TXTs to XLS or TXT Merge
Post by: poenie on August 17, 2007, 11:00:52 PM
I'm tring to merge 4 txt files to 1 file (either a xls or txt) Its easy to do, but the output file list the files contents under each other.  Is there dos code where by these files can be listed next to each other, eg xls into coloms and/or txt tab deliminated.

eg.

1.txt = 1,2,3                   >>>>  Output file           1      A
2.txt = A,B,C                                                          2     B
                                                                              3     C

Poenie
Title: Re: TXTs to XLS or TXT Merge
Post by: DeltaSlaya on August 18, 2007, 05:24:23 AM
Yea I'll try do something in batch, it might take a while...
Title: Re: TXTs to XLS or TXT Merge
Post by: DeltaSlaya on August 18, 2007, 05:27:20 AM
Ok I'll do one where the input files are delimited by ","s and I think the input files are going to have to be the same length.

One question, WTH is this going to be used for, I can't see any use except homework?
Title: Re: TXTs to XLS or TXT Merge
Post by: ghostdog74 on August 18, 2007, 07:03:36 AM
warning: not tested with different data formats. Only test with supplied example input files.
Code: [Select]
Option Explicit
Dim objFSO,myFile1,myFile2,myLine,strF1,strF2
Dim objF1, objF2,array1,array2,bigArray1(),bigArray2(),i,j
Set objFSO=CreateObject("Scripting.FileSystemObject")
myFile1 = "C:\temp\1.txt"
myFile2 = "C:\temp\2.txt"
Set objF1=objFSO.OpenTextFile(myFile1,1)
i=0
Do Until objF1.AtEndOfLine
array1=Split(objF1.ReadLine,",")
ReDim Preserve bigArray1(i)
bigArray1(i) = array1
i=i+1
Loop
i=0
Set objF2=objFSO.OpenTextFile(myFile2,1)
Do Until objF2.AtEndOfLine
array2=Split(objF2.ReadLine,",")
ReDim Preserve bigArray2(i)
bigArray2(i) = array2
i=i+1
Loop
For j=LBound(bigArray1) To UBound(bigArray1)
    For i=LBound(array1) To UBound(array1)
WScript.Echo bigArray1(j)(i),bigArray2(j)(i)
Next
Next
set objF1=Nothing
set objF2=Nothing
set objFSO=Nothing

output:
Code: [Select]
C:\temp>more 1.txt
1,2,3
4,5,6

C:\temp>more 2.txt
A,B,c
D,E,F

C:\temp>cd \vbscript

C:\vbscript>cscript /nologo test.vbs
1 A
2 B
3 c
4 D
5 E
6 F

C:\vbscript>
Title: Re: TXTs to XLS or TXT Merge
Post by: DeltaSlaya on August 18, 2007, 03:33:50 PM
Yea I wasn't able to figure out how to make this in Batch without being a max of 26 or having a bunch of variables.
Title: Re: TXTs to XLS or TXT Merge
Post by: ghostdog74 on August 18, 2007, 06:01:46 PM
Yea I wasn't able to figure out how to make this in Batch without being a max of 26 or having a bunch of variables.
why use batch? there are many other excellent program languages around that fills in what batch lacks.
Title: Re: TXTs to XLS or TXT Merge
Post by: DeltaSlaya on August 18, 2007, 06:06:11 PM
I know.. The OP asked for batch so..

I know C# but I don't think you can use it for stuff like this..
Title: Re: TXTs to XLS or TXT Merge
Post by: ghostdog74 on August 18, 2007, 06:11:58 PM
I know.. The OP asked for batch so..

I know C# but I don't think you can use it for stuff like this..
i think that if you know and its easier to do, just post. This forum is for learning , isn't it.?:) even if OP cannot or don't know how to use C#.