From: shags72 on
I want to merge 2 files together and I was wondering if there was a
way to do this without processing each line from the appended file to
the host file with gets and puts? I am using 8.1tcl version. Thanks!
From: jr4412 on
On Jul 19, 3:23 pm, shags72 <shags...(a)hotmail.com> wrote:
> I want to merge 2 files together and I was wondering if there was a
> way to do this without processing each line from the appended file to
> the host file with gets and puts? I am using 8.1tcl version. Thanks!

the following will work if you do not require any processing:

% exec cat file1 file2 > file3

is this what you meant?
From: Hai Vu on
On Jul 19, 7:23 am, shags72 <shags...(a)hotmail.com> wrote:
> I want to merge 2 files together and I was wondering if there was a
> way to do this without processing each line from the appended file to
> the host file with gets and puts? I am using 8.1tcl version. Thanks!

Please clarify what you meant by merge. If you want to append the
contents of one file to the other, here is a quick and dirty way:

package require fileutil
fileutil::appendToFile file1 [fileutil::cat file2]

These two lines read the contents of file2 and append to file1. Please
note that this is a "quick-and-dirty" solution which might not work if
file2 is large. Neither does it check for any error.
Hai
From: shags72 on
On Jul 19, 11:05 am, Hai Vu <wuh...(a)gmail.com> wrote:
> On Jul 19, 7:23 am, shags72 <shags...(a)hotmail.com> wrote:
>
> > I want to merge 2 files together and I was wondering if there was a
> > way to do this without processing each line from the appended file to
> > the host file with gets and puts? I am using 8.1tcl version. Thanks!
>
> Please clarify what you meant by merge. If you want to append the
> contents of one file to the other, here is a quick and dirty way:
>
> package require fileutil
> fileutil::appendToFile file1 [fileutil::cat file2]
>
> These two lines read the contents of file2 and append to file1. Please
> note that this is a "quick-and-dirty" solution which might not work if
> file2 is large. Neither does it check for any error.
> Hai

Well what I really need to do is open a file and put something at the
top of that file. But didn't think that was possible.

I cannot use exec command as the tcl I am using is embedded and it
freezes up my ap sporadically. So am not even sure if fileutil is in
the embedded tcl. The file size could be large but it is just text so
I guess it would depend on what you consider large.

What would be the difference between the exec cat and the fileutil?
New coder here and I don't get into this file stuff much. Mainly just
do the if and else stuff.
From: Glenn Jackman on
At 2010-07-19 12:28PM, "shags72" wrote:
> Well what I really need to do is open a file and put something at the
> top of that file. But didn't think that was possible.

"fcopy" is what you're looking for:

set new [open new_file w]
set top [open file_to_put_at_top r]
set rest [open file_to_follow_top r]

fcopy $top $new
fcopy $rest $new

close $new
close $top
close $rest

file rename -force $new $rest


--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous