Prev: Need help to uninstall TCL 8.5.8
Next: multiple files into one file based on unique entry in one of the files
From: Cesear on 18 Mar 2010 08:52 On Mar 17, 9:02 am, Arjen Markus <arjen.markus...(a)gmail.com> wrote: > On 17 mrt, 13:47, Cesear <ces...(a)gmail.com> wrote: > > > I have 4 flat files where each field is separated by a pipe |. In > > each file the second field has a unique value that is in all the > > files. Each line is terminated by a newline. I what to combine each > > file and create one file. In this one file, there should be one line > > for each "unique" entry in that was found in the second file. I was > > able to do this in MS access by creating each file as table and > > linking the "unique" field in the 2nd file to the other files. I want > > do this in Tcl, so I can automate the process. Come some please point > > me in a starting direction? I know enough Tcl to get by, but not much > > in the I/O region. Any ideas or would be great! > > > Thx!! > > What you could do is: > > while {[gets $infile line] } { > set fields [split $line |] > set uniqueId [lindex $fields 1] > set data1($uniqueId) [lreplace $fields 1 1] > > } > > (Same for the other files) > > Now you have four arrays, data1, ... data4, that hold the > non-unique information for each unique ID. > > Joining them into one file: > > foreach id [array names data1] { > puts $outfile [join [concat $id $data1($id) $data2($id) > $data3($id) $data4($id)] |] > > } > > Or code along those lines - this is mostly a sketch. > > Regards, > > Arjen Arjen u code works well, but I need to modify it some. I need to be able to join the final file and only show the unqiueid at the beginning of the row. How can I do that?
From: Alexandre Ferrieux on 18 Mar 2010 10:32 On Mar 18, 1:52 pm, Cesear <ces...(a)gmail.com> wrote: > > Arjen u code works well, but I need to modify it some. I need to be > able to join the final file and only show the unqiueid at the > beginning of the row. How can I do that? Instead of repeating the question 4 times, just post the full example with inputs *and* wanted output. -Alex
From: Cesear on 18 Mar 2010 11:12 On Mar 18, 10:32 am, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> wrote: > On Mar 18, 1:52 pm, Cesear <ces...(a)gmail.com> wrote: > > > > > Arjen u code works well, but I need to modify it some. I need to be > > able to join the final file and only show the unqiueid at the > > beginning of the row. How can I do that? > > Instead of repeating the question 4 times, just post the full example > with inputs *and* wanted output. > > -Alex Sorry must have hit the reply too many times :) Ok here is what I want, just data no English :) --->>> File ONE--> V0100|NAME1|blah|blah| V0102|NAME2|blah|blah| File TWO--> V0100|NAME1|chargeX|blah| V0100|NAME1|chargeY|blah| V0102|NAME2|chargeX|blah| V0102|NAME2|chargeY|blah| V0100|NAME1|blahcharge|blah| V0102|NAME2|blahcahrge|blah| The FINAL OUTPUT, I want to look like this--> V0100|NAME1|blah|blah|chargeX|blah| V0100|NAME1|blah|blah|chargeY|blah| V0102|NAME2|blah|blah|chargeX|blah| V0102|NAME2|blah|blah|chargeY|blah| V0100|NAME1|blah|blah|blahcharge|blah| V0102|NAME2|blah|blah|blahcahrge|blah|
From: Cesear on 18 Mar 2010 11:12 On Mar 18, 10:32 am, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> wrote: > On Mar 18, 1:52 pm, Cesear <ces...(a)gmail.com> wrote: > > > > > Arjen u code works well, but I need to modify it some. I need to be > > able to join the final file and only show the unqiueid at the > > beginning of the row. How can I do that? > > Instead of repeating the question 4 times, just post the full example > with inputs *and* wanted output. > > -Alex Sorry must have hit the reply too many times :) Ok here is what I want, just data no English :) --->>> File ONE--> V0100|NAME1|blah|blah| V0102|NAME2|blah|blah| File TWO--> V0100|NAME1|chargeX|blah| V0100|NAME1|chargeY|blah| V0102|NAME2|chargeX|blah| V0102|NAME2|chargeY|blah| V0100|NAME1|blahcharge|blah| V0102|NAME2|blahcahrge|blah| The FINAL OUTPUT, I want to look like this--> V0100|NAME1|blah|blah|chargeX|blah| V0100|NAME1|blah|blah|chargeY|blah| V0102|NAME2|blah|blah|chargeX|blah| V0102|NAME2|blah|blah|chargeY|blah| V0100|NAME1|blah|blah|blahcharge|blah| V0102|NAME2|blah|blah|blahcahrge|blah|
From: Cesear on 18 Mar 2010 11:27 On Mar 18, 10:32 am, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> wrote: > On Mar 18, 1:52 pm, Cesear <ces...(a)gmail.com> wrote: > > > > > Arjen u code works well, but I need to modify it some. I need to be > > able to join the final file and only show the unqiueid at the > > beginning of the row. How can I do that? > > Instead of repeating the question 4 times, just post the full example > with inputs *and* wanted output. > > -Alex Sorry must have hit the reply too many times :) Ok here is what I want, just data no English :) --->>> File ONE--> V0100|NAME1|blah|blah| V0102|NAME2|blah|blah| File TWO--> V0100|NAME1|chargeX|blah| V0100|NAME1|chargeY|blah| V0102|NAME2|chargeX|blah| V0102|NAME2|chargeY|blah| V0100|NAME1|blahcharge|blah| V0102|NAME2|blahcahrge|blah| The FINAL OUTPUT, I want to look like this--> V0100|NAME1|blah|blah|chargeX|blah| V0100|NAME1|blah|blah|chargeY|blah| V0102|NAME2|blah|blah|chargeX|blah| V0102|NAME2|blah|blah|chargeY|blah| V0100|NAME1|blah|blah|blahcharge|blah| V0102|NAME2|blah|blah|blahcahrge|blah|
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: Need help to uninstall TCL 8.5.8 Next: multiple files into one file based on unique entry in one of the files |