Computer Hope
Microsoft => Microsoft DOS => Topic started 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
-
Yea I'll try do something in batch, it might take a while...
-
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?
-
warning: not tested with different data formats. Only test with supplied example input files.
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:
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>
-
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.
-
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.
-
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 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#.