From: Cesear on
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
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
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
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
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