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 17 Mar 2010 08:47 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!!
From: Arjen Markus on 17 Mar 2010 09:02 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
From: Alexandre Ferrieux on 17 Mar 2010 09:16 On Mar 17, 1:47 pm, 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! Your description is a bit unclear, please provide an example. -Alex
From: Larry W. Virden on 17 Mar 2010 09:37 On Mar 17, 8:47 am, 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. What you are describing sounds like the unix join command.
From: Arjen Markus on 17 Mar 2010 09:42 On 17 mrt, 14:05, Glenn Jackman <gle...(a)ncf.ca> wrote: > At 2010-03-17 09:02AM, "Arjen Markus" wrote: > > > while {[gets $infile line] } { > > Note, should be > while {[gets $infile line] != -1} { > > -- > Glenn Jackman > Write a wise saying and your name will live forever. -- Anonymous Argh, yes, or [gets ...] >= 0. Regards, Arjen
|
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 |