f



Append a file to an existing file

Hi there

I am wondering if there is a simple command in Tcl that I can append a
file to an existing file, or combine two files into one file ?


Thanks for the help.

Regards
S-Y. Chen

0
shenyeh_chen (102)
8/3/2009 4:12:26 PM
comp.lang.tcl 23429 articles. 2 followers. Post Follow

5 Replies
869 Views

Similar Articles

[PageSpeed] 19

S-Y. Chen wrote:
> Hi there
> 
> I am wondering if there is a simple command in Tcl that I can append a
> file to an existing file, or combine two files into one file ?
> 
> 
> Thanks for the help.
> 
> Regards
> S-Y. Chen
> 

Here's one way...

- [open] fileA in append mode
- [open] fileB in read only mode
- [read] the contents of fileB and write it to fileA using [puts]
- [close] both files

So, the man pages on [open], [read], [puts], and [close] should give you 
all you need.

Jeff

0
jeff_godfrey (836)
8/3/2009 4:45:39 PM
On Aug 4, 12:45=A0am, Jeff Godfrey <jeff_godf...@pobox.com> wrote:
> S-Y. Chen wrote:
> > Hi there
>
> > I am wondering if there is a simple command in Tcl that I can append a
> > file to an existing file, or combine two files into one file ?
>
> > Thanks for the help.
>
> > Regards
> > S-Y. Chen
>
> Here's one way...
>
> - [open] fileA in append mode
> - [open] fileB in read only mode
> - [read] the contents of fileB and write it to fileA using [puts]
> - [close] both files
>
> So, the man pages on [open], [read], [puts], and [close] should give you
> all you need.
>
> Jeff

I know I can do it through open, read and close.....just want to see
if there is a command like

copy a+b c

Maybe not...so......I will open, read and close it anyway........

Thanks for the help.

Regards
S-Y. Chen
0
shenyeh_chen (102)
8/3/2009 5:20:43 PM
S-Y. Chen <shenyeh_chen@hotmail.com> wrote:
> On Aug 4, 12:45 am, Jeff Godfrey <jeff_godf...@pobox.com> wrote:
>> S-Y. Chen wrote:
>> > Hi there
>> > I am wondering if there is a simple command in Tcl that I can append a
>> > file to an existing file, or combine two files into one file ?
>> Here's one way...
>> - [open] fileA in append mode
>> - [open] fileB in read only mode

>> - [read] the contents of fileB and write it to fileA using [puts]
just these two steps have a shortcut: [fcopy]

>> - [close] both files

So: open fileA and fileB in their respective modes
    fcopy $inputFd $appendtoFd
    close both filedescriptors

>> So, the man pages on [open], [read], [puts], and [close] should give you
>> all you need.
same for fcopy, of course.

> copy a+b c
But that's three files: first, copy a to c (using [file copy a c]),
then use the recipe for appending b to c.

PS: if on unix, do it thusly:    exec cat a b > c
0
avl1 (2748)
8/3/2009 6:05:05 PM
O/H S-Y. Chen έγραψε:
> On Aug 4, 12:45 am, Jeff Godfrey <jeff_godf...@pobox.com> wrote:
>> S-Y. Chen wrote:
>>> Hi there
>>> I am wondering if there is a simple command in Tcl that I can append a
>>> file to an existing file, or combine two files into one file ?
>>> Thanks for the help.
>>> Regards
>>> S-Y. Chen
>> Here's one way...
>>
>> - [open] fileA in append mode
>> - [open] fileB in read only mode
>> - [read] the contents of fileB and write it to fileA using [puts]
>> - [close] both files
>>
>> So, the man pages on [open], [read], [puts], and [close] should give you
>> all you need.
>>
>> Jeff
> 
> I know I can do it through open, read and close.....just want to see
> if there is a command like
> 
> copy a+b c
> 
> Maybe not...so......I will open, read and close it anyway........
> 
> Thanks for the help.
> 
> Regards
> S-Y. Chen

If you tcllib, you can check the fileutil package:

package require fileutil

::fileutil::appendToFile b [::fileutil::cat a]

or

::fileutil::writeFile c [::fileutil::cat a b]

George
0
petasis (1405)
8/3/2009 7:00:37 PM
On Aug 4, 3:00=C2=A0am, Georgios Petasis <peta...@iit.demokritos.gr> wrote:
> O/H S-Y. Chen =CE=AD=CE=B3=CF=81=CE=B1=CF=88=CE=B5:
>
>
>
> > On Aug 4, 12:45 am, Jeff Godfrey <jeff_godf...@pobox.com> wrote:
> >> S-Y. Chen wrote:
> >>> Hi there
> >>> I am wondering if there is a simple command in Tcl that I can append =
a
> >>> file to an existing file, or combine two files into one file ?
> >>> Thanks for the help.
> >>> Regards
> >>> S-Y. Chen
> >> Here's one way...
>
> >> - [open] fileA in append mode
> >> - [open] fileB in read only mode
> >> - [read] the contents of fileB and write it to fileA using [puts]
> >> - [close] both files
>
> >> So, the man pages on [open], [read], [puts], and [close] should give y=
ou
> >> all you need.
>
> >> Jeff
>
> > I know I can do it through open, read and close.....just want to see
> > if there is a command like
>
> > copy a+b c
>
> > Maybe not...so......I will open, read and close it anyway........
>
> > Thanks for the help.
>
> > Regards
> > S-Y. Chen
>
> If you tcllib, you can check the fileutil package:
>
> package require fileutil
>
> ::fileutil::appendToFile b [::fileutil::cat a]
>
> or
>
> ::fileutil::writeFile c [::fileutil::cat a b]
>
> George

Thanks a lot !

S-Y. Chen
0
shenyeh_chen (102)
8/4/2009 4:30:26 AM
Reply:

Similar Artilces:

appending a new xml file to another existing xml file
Hei, I am having issue using DOM to appending a new xml file (new.xml) to another existing xml file (old.xml) without deleting the existing items in old.xml. I would like to have the new <items> append at the end of existing items at the old.xml. How can I do that? I am using php5 Thanks! Ofuuzo On Feb 18, 9:30 am, ofuu...@yahoo.no wrote: > Hei, > I am having issue using DOM to appending a new xml file (new.xml) to > another existing xml file (old.xml) without deleting the existing > items in old.xml. I would like to have the new <items> append at the > end of e...

Sourcing a TCL file from within a tcl file
I am a newbie which I am sure I don't need to state :) I am trying to create a variable with a TCL file that will source another tcl file when I type the variable name something like this if I enter A through my keyboard then source a.tcl Can someone show me how to do this thanks guy On Dec 10, 1:15=A0pm, guy <gcoletta2...@gmail.com> wrote: > I am a newbie which I am sure I don't need to state :) > > I am trying to create a variable with a TCL file that will source > another tcl file when I type the variable name > > something like this > > if I enter A through my keyboard =A0then source a.tcl > > Can someone show me how to do this > > thanks > guy What you are asking is not hard. Will your program have a graphical user interface? Aric On Dec 10, 3:26=A0pm, Aric Bills <aric.bi...@gmail.com> wrote: > On Dec 10, 1:15=A0pm, guy <gcoletta2...@gmail.com> wrote: > > > I am a newbie which I am sure I don't need to state :) > > > I am trying to create a variable with a TCL file that will source > > another tcl file when I type the variable name > > > something like this > > > if I enter A through my keyboard =A0then source a.tcl > > > Can someone show me how to do this > > > thanks > > guy > > What you are asking is not hard. =A0Will your program have a graphical > user interface? > > Aric no I am just using this script...

file exists / file not found
While playing with some code for another thread, I discovered that among the BASIC language diagnostics was the text FILE NOT FOUND. I am unable to find FILE EXISTS among the BASIC diagnostics. When I attempt a load of a non existent file, the drive error light blinks and the system issues a FILE NOT FOUND diagnostic. When I try to save data with a name of a file already on the disk, the drive error light blinks but no diagnostic is issued by the system. In both cases, the drive needs to be queried to retrieve the drive's diagnostic and to stop the drive error light from blinking. I ha...

Tcl file from .txt file
Hi, I have a excel file. I need to change the excel file in to tcl file. I did = change the excel file in to txt file. but unable to change the txt file in = to tcl file. let me know any idea to change the txt file in to tcl file or = directly from the excel file in to tcl file.=20 your help is much more appreciated. thank you. On 11/14/14, 1:30 PM, yenilsuwal@gmail.com wrote: > Hi, > > I have a excel file. I need to change the excel file in to tcl file. I did change the excel file in to txt file. but unable to change the txt file in to tcl file. let me know any idea to c...

FAQ 5.2: How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file?
This message is one of several periodic postings to comp.lang.perl.misc intended to make it easier for perl programmers to find answers to common questions. The core of this message represents an excerpt from the documentation provided with Perl. -------------------------------------------------------------------- 5.2: How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file? Use the Tie::File module, which is included in the standard distribution since Perl 5.8.0. ------------------------------------------...

FAQ 5.2 How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file?
This message is one of several periodic postings to comp.lang.perl.misc intended to make it easier for perl programmers to find answers to common questions. The core of this message represents an excerpt from the documentation provided with Perl. -------------------------------------------------------------------- 5.2: How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file? Use the Tie::File module, which is included in the standard distribution since Perl 5.8.0. ------------------------------------------...

Tcl 8.6 unexpected 'file exists'
I have a proc which takes a full path argument for a file. (one of the items returned from a glob) roughly: proc handlefile {path} { #puts stdout [file normalize $path] set fsize [file size $path] #...etc } Strangely... a particular file has problems with the above. The 'file size' call returns: could not read "/usr/local/xxx/www/yyy/Newsletter/050609/~ $sueme220509.htm" no such file or directory The 'file normalize' output is "/usr/local/virtual1/hosting/base/yy/ yyy/yyy/www/Newsletter/050609/~$sueme220509.htm" Both these paths are valid, and equivalent due to some soft symlinking - and both work just fine in an interactive tclsh with 'file size' returning a size and 'file exists' returning 1. The heisenbuggish thing is - that the mere act of using puts to display the normalized path (without actually using the normalized value anywhere); causes the problem to disappear. i.e uncommenting the 2nd line in the proc above causes file size to work as expected. I'm assuming this is a bug - but at this stage I don't know if the ~ or $ characters are relevant or if it just happened to occur on this strangely named file for some other reason. This problem occurs on FreeBSD with a Tcl 8.5.b1 checked out in january - and also with 8.6b1.1 from 2009-06-14 The bug doesn't occur when I use an 8.5a4 tclkit I'll report a bug for it if it turns out to be a new one - but I just thought I'd throw ...

file extention from file file location
Hi, I am new to perl (only working on this one problem) but I program in other languages. We have an upload script written in cgi. Can anyone tell me how to get the file extension from the variable $File1 (actual file location on uploader's computer) then find out if it is equal to "txt" Thanks in advance for not telling me to read the manual. Ron -- PLEASE NOTE: comp.infosystems.www.authoring.cgi is a SELF-MODERATED newsgroup. aa.net and boutell.com are NOT the originators of the articles and are NOT responsible for their content. HOW TO POST to co...

FAQ 5.2 How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file? #2 325998
This message is one of several periodic postings to comp.lang.perl.misc intended to make it easier for perl programmers to find answers to common questions. The core of this message represents an excerpt from the documentation provided with Perl. -------------------------------------------------------------------- 5.2: How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file? Use the Tie::File module, which is included in the standard distribution since Perl 5.8.0. ------------------------------------------...

FAQ 5.2 How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file? #3 554638
This is an excerpt from the latest version perlfaq5.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 5.2: How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file? Use the Tie::File module, which is included in the standard distribution since Perl 5.8.0. -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They are not necessarily experts in every domain where Perl might show up, so please include as much information as possible and relevant in any corrections. The perlfaq-workers also don't have access to every operating system or platform, so please include relevant details for corrections to examples that do not work on particular platforms. Working code is greatly appreciated. If you'd like to help maintain the perlfaq, see the details in perlfaq.pod. -- Posted via a free Usenet account from http://www.teranews.com ...

FAQ 5.2 How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file? #2 554047
This is an excerpt from the latest version perlfaq5.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 5.2: How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file? Use the Tie::File module, which is included in the standard distribution sinc...

GUI *.fig file deleted, *.m file still exists, can *.fig file be retrieved?
I created a GUI, but the *.fig file was deleted, the *.m or code file still exists, can *.fig file be retrieved or can I regenerate the *.fig file from the *.m file? I am using MATLAB 6.5 Release 13. Please Help! Brian Bird wrote: > > > I created a GUI, but the *.fig file was deleted, the *.m or code > file > still exists, can *.fig file be retrieved or can I regenerate the > *.fig file from the *.m file? I am using MATLAB 6.5 Release 13. > Please Help! No, however the file might still be on the hard disk. Google for "undelete". One of the first hits is <h...

Iteration through File.file? misses entries for which File.file?(entry) == true
Hello everyone, I'm new to Ruby, so I'm most likely making an elementary mistake. However, searching Google didn't help me find my answer, and after mucking around with irb I still haven't figured it out. I wrote a method that was intended to take all of the files in a given directory and put them into an array. Here's the code I wrote: def getFiles(dir) pwdFiles = Array.new Dir.foreach(dir) do |entry| pwdFiles.push(entry) if File.file?(entry) == true end end This works fine when called on the working directory --- that is, getFile...

opening file
Hello, This really drives me nuts. Im opening an input file, and Im testing if it was open successfully. Thats it! I know that the file that Im trying to open DOES NOT exist but Im getting NO error message. No matter what name I enter I get 'file opened successfully" Any clues? Thanks! #include <iostream.h> #include <stdlib.h> #include <stdio.h> #include <fstream.h> int main() { ifstream infile; char file_name[16]; printf("\nEnter file name: "); cin>>file_name; infile.open(file_name); if (infile.fail()) ...

Get path from FILE* of existing file
Hi all! I've got a FILE* pointing to an already opened file. I want to create a new file in the same directory where that file is. Is there any way of obtaining file path from FILE*? Many thanks/Alvaro "Alvaro Puente" <alvaro.puente-gonzalez@ece.ericsson.se> wrote in message news:bec2qn$8td$1@newstree.wise.edt.ericsson.se... > Hi all! > > I've got a FILE* pointing to an already opened file. > I want to create a new file in the same directory where > that file is. > > Is there any way of obtaining file path from FILE*? From the C FAQ: 19.15: ...

create a zip file with existing files in it
I try the zip example described in the doc. It worked that way. But now I want to add existing files to a new created zip. first the code <code> void OBApp::Test () { wxFFileOutputStream out(_T("C:\\test.zip")); wxZipOutputStream zip(out); wxTextOutputStream txt(zip); // ?? wxFileInputStream strFile("C:\\autoexec.bat"); wxString sep(wxFileName::GetPathSeparator()); zip.PutNextEntry(_T("C:\\autoexec.bat")); txt << _T("Some text for entry1.txt\n"); zip.PutNextEn...

Error appending files to a zip file
------=_Part_8079_21160516.1214328831692 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi All, I'm trying to modify a zip file, appending new files to it. I' ve copied this example: http://docs.wxwidgets.org/stable/wx_wxarc.html#wxarcmodify. But It throw an error when try to Commit the new file. The error says:"error 32: the process does not have access to the file because it is being used by another process" Could someone tell me what I'm doing wrong? Here is the code: std::auto_ptr<wxFFi...

Testing file size and file exist?
I want to perform a couple of statements if either the file does not exist OR the file size of a given file is equal 0. Currently the best solution I can imagine is something like: if [! -e myfile.dat ]; then echo "File not existing or file size = 0" do_something else filesize=`wc -c myfile.dat` echo "filesize=$filesize" if [ $filesize = 0 ]; then echo "File not existing or file size = 0" do_something fi fi The first problem I encounter is that the back ticks are NOT recognized by the shell interpreter. filesize contains blank af...

Cannot create a file when that file already exists
I built a dummy Win32 Smart Device application from the Visual Studio 2005 wizard and upon deploying the application to the real Pocket PC device connected with ActiveSync 4.0, I got the following error message in the output console: "Cannot create a file when that file already exists". I had this error even the first time I deployed the application; thus it is not a problem because of a file I am trying to deploy that already exists. I did the same test on the Pocket PC 2003 emulator and everything works fine. Do you know to which file the error message is referring to? ...

write file + input file + write file
Hi, I want to write some latex command to a file (file1), input the file at the end of the document. These command shall write to another file (file2) and at a second run I use the file2. Whatever I have tried nothing works and I don't known why. The goal is to save a set of special commands and run them at the end of the document, because they use some values which are only available at the end! Can anybody please help me with that? Thanks in advance! I should be something like: \begin{document} \usepackage{style} \input{file2} %file exists from a previous run \end{document} style.sty: \newwrite\fileone \openout\fileone=file1.out \newwrite\filetwo \openout\filetwo=file2.out \newcommand{\writetofiletwo}[1]{% \write\filetwo{#1}% } \newcommand{\writetofileone}[1]{% \write\fileone{\writetofiletwo{some text}}% } \AtEndDocument{\closeout\fileone% \input{file1}% \closeout\filetwo% } Problem solved :-) \immediate\closeout before \input was required. greenux wrote: > Hi, > I want to write some latex command to a file (file1), input the file > at the end of the document. These command shall write to another file > (file2) and at a second run I use the file2. > Whatever I have tried nothing works and I don't known why. The goal is > to save a set of special commands and run them at the end of the > document, because they use some values which are only available at the > end! > Can anybody please help me with that? > Thanks in advance! &...

File share, File Sharing, File Host
http://fileuplo.de File share, File Sharing, File Host -- questo articolo e` stato inviato via web dal servizio gratuito http://www.newsland.it/news segnala gli abusi ad abuse@newsland.it ...

object files, header files, source files?
I can't find any books describing the anatomy of C/C++ programs. What is an object file? Can it be generated from a header file?, what is linking?, why does a source file need an object file? etc. I have looked in The C programming Language, The C++ Programming Language, Accelerated C++, GNU make etc but they don't describe these basic subject. Any literature that covers these subjects? saneman wrote: > I can't find any books describing the anatomy of C/C++ programs. What is > an object file? Can it be generated from a header file?, what is > linking?, why does a s...

How to copy a file to a file with a prefixed file name
I'm trying to write a program that will archive selected files to an archive directory. The files in the archive directory will have a prefix in the format yyyymmdd-hhmmss-filename.ext. So, if the file is called "somefile.dat", then the filename in the archive directory should be "20090522-164325-somefile.dat". I'm using Clipper's COPY FILE command to do the copy. I can't figure out how to get the prefix in front of the file name. Creating the prefix string is no problem, but I can't figure out how to tack that onto the front of the filename. If I...

copy data from .xlsx/.xls file as new records to an EXISTING .dbf file (via programming in a clipper 5.3 .PRG file)
.xlsx/.xls data be saved as new records in an existing .dbf file (to be done by programming in a clipper 5.3 .prg file) i have this in an .xlsx/.xls file: Name Hours Date Assign OPE Comments XXT 4.50 20/12/2014 AUDIT Conveyance checked 1314 books P01 12.05 23/12/2014 DUED1 Lunch computed net worth XXT .10 23/12/2014 M&A merged stock... 90H 2.00 02/01/2015 AUDIT Xerox found discrepancies can the 4 (or more records) be read & saved as 4 ...

Web resources about - Append a file to an existing file - comp.lang.tcl

Pre-existing condition - Wikipedia, the free encyclopedia
J. James Rohack, president of the American Medical Association , has stated on a Fox News Sunday interview that exclusions, based upon these ...

STUDY: Facebook More Effective In Driving Viewers To New Shows Than Existing Ones
... television and Facebook and other social networks, finding that social media are more effective at driving viewership of new shows than existing ...

A New Way To Re-Engage Your Existing Mobile App Users
Today we are introducing a new way to re-engage your mobile app users with Facebook ads. You can now advertise to people who have taken specific ...

Facebook expands IPO with additional 83.8M shares from existing stockholders
... according to an eighth amendment to its S-1 filing with the Securities and Exchange Commission. Most of these shares are being sold by existing ...

How do you grow your brand through existing clients?
Anna Farmery and I are doing a podcast this week on how to leverage happy clients to grow your brand. We&#39;d love to include your advice in ...

Video Zoom - Apply Zoom To Existing Videos, Crop on the App Store on iTunes
Get Video Zoom - Apply Zoom To Existing Videos, Crop on the App Store. See screenshots and ratings, and read customer reviews.

“The important thing is not to stop questioning. Curiosity has its own reason for existing.” Albert Einstein ...
Pretty dreary here today, but this stop sign caught my attention. Bright, vivid colors can draw attention and add "pop" to a photo. Make a photo ...

Shorten unveils Labor election policy: No more negative gearing existing homes
... policy that Opposition Leader Bill Shorten says will save the federal budget $32 billion over a decade. But, from July 2017, buyers of existing ...

US existing home sales fall in August
... as investors retreated from real estate and first-time buyers remained scarce. The National Association of Realtors says sales of existing ...

Leaked cabinet advice shows existing road funding to be relaunched as new
... under question, after a leaked cabinet submission showed Roads Minister Luke Donnellan&#10003;&#8203; is preparing to simply repackage an existing ...

Resources last updated: 3/13/2016 11:26:34 AM