Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #13160 > unrolled thread

Re: Export with append??

Started by"Maarten van der Burgt" <Maarten.vanderBurgt@kla-tencor.com>
First post2013-01-16 06:38 +0000
Last post2013-01-18 05:49 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Export with append?? "Maarten van der Burgt" <Maarten.vanderBurgt@kla-tencor.com> - 2013-01-16 06:38 +0000
    Re: Export with append?? Szabolcs <szhorvat@gmail.com> - 2013-01-17 04:15 +0000
    Re: Export with append?? Murray Eisenberg <murray@math.umass.edu> - 2013-01-18 05:49 +0000
    Re: Export with append?? Szabolcs Horvát <szhorvat@gmail.com> - 2013-01-18 05:49 +0000

#13160 — Re: Export with append??

From"Maarten van der Burgt" <Maarten.vanderBurgt@kla-tencor.com>
Date2013-01-16 06:38 +0000
SubjectRe: Export with append??
Message-ID<kd5hu2$jjp$1@smc.vnet.net>
Dear Alexei,

Thanks for your help. Hope the Wolfram folks are reading this as well.
Something simple like this should really be an option in the function
Export.

Meanwhile I found back something similar for XLS files in my knowledge
base:

XLAppend[oldfile_, newfile_, newdata_] :=  Module[

{sheets, olddata, completedata},

  sheets = Import[oldfile, "Sheets"];

  olddata = {#, Import[oldfile, {"Sheets", #}]} & /@ sheets;

  completedata = Join[olddata, newdata];

Export[newfile, Rule @@@ completedata]

]



Best regards,



Maarten





Maarten van der Burgt

Product Engineering  - ICOS Division

________________________________

KLA-Tencor | ICOS Division
Tel: +32 16 398220 | Direct: +32 16 398263 | Fax: +32 16 400067

KLA-TENCOR (Belgium) - Haasrode Research Park 1112 - Esperantolaan 8 -
B-3001 Leuven - BELGIUM

Mail: maarten.vanderburgt@kla-tencor.com







From: Alexei Boulbitch [mailto:Alexei.Boulbitch@iee.lu]
Sent: maandag 14 januari 2013 10:22
Cc: Maarten van der Burgt
Subject: Re: Export with append??





Hallo,



With a command like



Export["myfile.dat", results, "List" ]



is there a way to append the results to an existing myfile.dat, rather

than creating or overwriting an existing file?



thanks for your help,



Maarten





Hi, Maarten,

A simple workaround is to import your file, append a new file to it and
then - to export the combined list. Assume that your mathematica
notebook entitled "trialImportExport.nb"  is situated in the same folder
as the already existing list entitled "myfile.dat".

To be precise I generated the file myfile.dat with the list:

{25, 36, 49}

in it. Assume further that I want to append the list

{a,b,c}

to it. Then the code



lst1=Import[NotebookDirectory[]<>"myfile.dat"]//Flatten;

lst2={a,b,c};

lst3=Append[lst1,lst2]//Flatten;

Export[NotebookDirectory[]<>"myfileNew.dat",lst3]



Does the job. The output cell below:



D:\Documents and Settings\ABo\My
Documents\Works\Mathematica_works\Examples\TrialFiles\myfileNew.dat



shows that the file has been successfully exported.

I intentionally gave the resulting file a new name, "myfileNew.dat", to
check the result, but the old name can also be given to it.



Have fun, Alexei





Alexei BOULBITCH, Dr., habil.

IEE S.A.

ZAE Weiergewan,

11, rue Edmond Reuter,

L-5326 Contern, LUXEMBOURG



Office phone :  +352-2454-2566

Office fax:       +352-2454-3566

mobile phone:  +49 151 52 40 66 44



e-mail: alexei.boulbitch@iee.lu





[toc] | [next] | [standalone]


#13178

FromSzabolcs <szhorvat@gmail.com>
Date2013-01-17 04:15 +0000
Message-ID<kd7tsb$q3p$1@smc.vnet.net>
In reply to#13160
Hello Maarten,

In fact there is a simple way to make Export append rather than overwrite.  Please see here:

http://mathematica.stackexchange.com/a/2228/12

You just need to use a stream in place of the file name:

file = OpenAppend["out.txt"]

Export[file, data, "CSV"];
WriteString[file, "\n"];

Close[file]

On Wednesday, 16 January 2013 01:38:58 UTC-5, Maarten van der Burgt  wrote:
> Dear Alexei,
> 
> 
> 
> Thanks for your help. Hope the Wolfram folks are reading this as well.
> 
> Something simple like this should really be an option in the function
> 
> Export.
> 
> 
> 
> Meanwhile I found back something similar for XLS files in my knowledge
> 
> base:
> 
> 
> 
> XLAppend[oldfile_, newfile_, newdata_] :=  Module[
> 
> 
> 
> {sheets, olddata, completedata},
> 
> 
> 
>   sheets = Import[oldfile, "Sheets"];
> 
> 
> 
>   olddata = {#, Import[oldfile, {"Sheets", #}]} & /@ sheets;
> 
> 
> 
>   completedata = Join[olddata, newdata];
> 
> 
> 
> Export[newfile, Rule @@@ completedata]
> 
> 
> 
> ]
> 
> 
> 
> 
> 
> 
> 
> Best regards,
> 
> 
> 
> 
> 
> 
> 
> Maarten
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Maarten van der Burgt
> 
> 
> 
> Product Engineering  - ICOS Division
> 
> 
> 
> ________________________________
> 
> 
> 
> KLA-Tencor | ICOS Division
> 
> Tel: +32 16 398220 | Direct: +32 16 398263 | Fax: +32 16 400067
> 
> 
> 
> KLA-TENCOR (Belgium) - Haasrode Research Park 1112 - Esperantolaan 8 -
> 
> B-3001 Leuven - BELGIUM
> 
> 
> 
> Mail: maarten.vanderburgt@kla-tencor.com
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> From: Alexei Boulbitch [mailto:Alexei.Boulbitch@iee.lu]
> 
> Sent: maandag 14 januari 2013 10:22
> 
> Cc: Maarten van der Burgt
> 
> Subject: Re: Export with append??
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Hallo,
> 
> 
> 
> 
> 
> 
> 
> With a command like
> 
> 
> 
> 
> 
> 
> 
> Export["myfile.dat", results, "List" ]
> 
> 
> 
> 
> 
> 
> 
> is there a way to append the results to an existing myfile.dat, rather
> 
> 
> 
> than creating or overwriting an existing file?
> 
> 
> 
> 
> 
> 
> 
> thanks for your help,
> 
> 
> 
> 
> 
> 
> 
> Maarten
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Hi, Maarten,
> 
> 
> 
> A simple workaround is to import your file, append a new file to it and
> 
> then - to export the combined list. Assume that your mathematica
> 
> notebook entitled "trialImportExport.nb"  is situated in the same folder
> 
> as the already existing list entitled "myfile.dat".
> 
> 
> 
> To be precise I generated the file myfile.dat with the list:
> 
> 
> 
> {25, 36, 49}
> 
> 
> 
> in it. Assume further that I want to append the list
> 
> 
> 
> {a,b,c}
> 
> 
> 
> to it. Then the code
> 
> 
> 
> 
> 
> 
> 
> lst1=Import[NotebookDirectory[]<>"myfile.dat"]//Flatten;
> 
> 
> 
> lst2={a,b,c};
> 
> 
> 
> lst3=Append[lst1,lst2]//Flatten;
> 
> 
> 
> Export[NotebookDirectory[]<>"myfileNew.dat",lst3]
> 
> 
> 
> 
> 
> 
> 
> Does the job. The output cell below:
> 
> 
> 
> 
> 
> 
> 
> D:\Documents and Settings\ABo\My
> 
> Documents\Works\Mathematica_works\Examples\TrialFiles\myfileNew.dat
> 
> 
> 
> 
> 
> 
> 
> shows that the file has been successfully exported.
> 
> 
> 
> I intentionally gave the resulting file a new name, "myfileNew.dat", to
> 
> check the result, but the old name can also be given to it.
> 
> 
> 
> 
> 
> 
> 
> Have fun, Alexei
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Alexei BOULBITCH, Dr., habil.
> 
> 
> 
> IEE S.A.
> 
> 
> 
> ZAE Weiergewan,
> 
> 
> 
> 11, rue Edmond Reuter,
> 
> 
> 
> L-5326 Contern, LUXEMBOURG
> 
> 
> 
> 
> 
> 
> 
> Office phone :  +352-2454-2566
> 
> 
> 
> Office fax:       +352-2454-3566
> 
> 
> 
> mobile phone:  +49 151 52 40 66 44
> 
> 
> 
> 
> 
> 
> 
> e-mail: alexei.boulbitch@iee.lu

[toc] | [prev] | [next] | [standalone]


#13186

FromMurray Eisenberg <murray@math.umass.edu>
Date2013-01-18 05:49 +0000
Message-ID<kdanpi$3cv$1@smc.vnet.net>
In reply to#13160
But surely appending like that won't work for many export formats. E.g., I hesitate to think what it might do to a PDF export.

On Jan 16, 2013, at 11:16 PM, Szabolcs <szhorvat@gmail.com> wrote:

> Hello Maarten,
>
> In fact there is a simple way to make Export append rather than overwrite.  Please see here:
>
> http://mathematica.stackexchange.com/a/2228/12
>
> You just need to use a stream in place of the file name:
>
> file = OpenAppend["out.txt"]
>
> Export[file, data, "CSV"];
> WriteString[file, "\n"];
>
> Close[file]
>
> On Wednesday, 16 January 2013 01:38:58 UTC-5, Maarten van der Burgt  wrote:
>> Dear Alexei,
>>
>>
>>
>> Thanks for your help. Hope the Wolfram folks are reading this as well.
>>
>> Something simple like this should really be an option in the function
>>
>> Export.
>>
>>
>>
>> Meanwhile I found back something similar for XLS files in my knowledge
>>
>> base:
>>
>>
>>
>> XLAppend[oldfile_, newfile_, newdata_] :=  Module[
>>
>>
>>
>> {sheets, olddata, completedata},
>>
>>
>>
>>  sheets = Import[oldfile, "Sheets"];
>>
>>
>>
>>  olddata = {#, Import[oldfile, {"Sheets", #}]} & /@ sheets;
>>
>>
>>
>>  completedata = Join[olddata, newdata];
>>
>>
>>
>> Export[newfile, Rule @@@ completedata]
>>
>>
>>
>> ]
>>
>>
>>
>>
>>
>>
>>
>> Best regards,
>>
>>
>>
>>
>>
>>
>>
>> Maarten
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> Maarten van der Burgt
>>
>>
>>
>> Product Engineering  - ICOS Division
>>
>>
>>
>> ________________________________
>>
>>
>>
>> KLA-Tencor | ICOS Division
>>
>> Tel: +32 16 398220 | Direct: +32 16 398263 | Fax: +32 16 400067
>>
>>
>>
>> KLA-TENCOR (Belgium) - Haasrode Research Park 1112 - Esperantolaan 8 =
-
>>
>> B-3001 Leuven - BELGIUM
>>
>>
>>
>> Mail: maarten.vanderburgt@kla-tencor.com
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> From: Alexei Boulbitch [mailto:Alexei.Boulbitch@iee.lu]
>>
>> Sent: maandag 14 januari 2013 10:22
>>
>> Cc: Maarten van der Burgt
>>
>> Subject: Re: Export with append??
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> Hallo,
>>
>>
>>
>>
>>
>>
>>
>> With a command like
>>
>>
>>
>>
>>
>>
>>
>> Export["myfile.dat", results, "List" ]
>>
>>
>>
>>
>>
>>
>>
>> is there a way to append the results to an existing myfile.dat, rather
>>
>>
>>
>> than creating or overwriting an existing file?
>>
>>
>>
>>
>>
>>
>>
>> thanks for your help,
>>
>>
>>
>>
>>
>>
>>
>> Maarten
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> Hi, Maarten,
>>
>>
>>
>> A simple workaround is to import your file, append a new file to it and
>>
>> then - to export the combined list. Assume that your mathematica
>>
>> notebook entitled "trialImportExport.nb"  is situated in the same folder
>>
>> as the already existing list entitled "myfile.dat".
>>
>>
>>
>> To be precise I generated the file myfile.dat with the list:
>>
>>
>>
>> {25, 36, 49}
>>
>>
>>
>> in it. Assume further that I want to append the list
>>
>>
>>
>> {a,b,c}
>>
>>
>>
>> to it. Then the code
>>
>>
>>
>>
>>
>>
>>
>> lst1=Import[NotebookDirectory[]<>"myfile.dat"]//Flatten;
>>
>>
>>
>> lst2={a,b,c};
>>
>>
>>
>> lst3=Append[lst1,lst2]//Flatten;
>>
>>
>>
>> Export[NotebookDirectory[]<>"myfileNew.dat",lst3]
>>
>>
>>
>>
>>
>>
>>
>> Does the job. The output cell below:
>>
>>
>>
>>
>>
>>
>>
>> D:\Documents and Settings\ABo\My
>>
>> Documents\Works\Mathematica_works\Examples\TrialFiles\myfileNew.dat
>>
>>
>>
>>
>>
>>
>>
>> shows that the file has been successfully exported.
>>
>>
>>
>> I intentionally gave the resulting file a new name, "myfileNew.dat", to
>>
>> check the result, but the old name can also be given to it.
>>
>>
>>
>>
>>
>>
>>
>> Have fun, Alexei
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> Alexei BOULBITCH, Dr., habil.
>>
>>
>>
>> IEE S.A.
>>
>>
>>
>> ZAE Weiergewan,
>>
>>
>>
>> 11, rue Edmond Reuter,
>>
>>
>>
>> L-5326 Contern, LUXEMBOURG
>>
>>
>>
>>
>>
>>
>>
>> Office phone :  +352-2454-2566
>>
>>
>>
>> Office fax:       +352-2454-3566
>>
>>
>>
>> mobile phone:  +49 151 52 40 66 44
>>
>>
>>
>>
>>
>>
>>
>> e-mail: alexei.boulbitch@iee.lu

---
Murray Eisenberg                                    
murray@math.umass.edu
Mathematics & Statistics Dept.      
Lederle Graduate Research Tower            phone 413 549-1020 (H)
University of Massachusetts                               413 5 (W)
710 North Pleasant Street                         fax   413 545-1801
Amherst, MA 01003-9305





[toc] | [prev] | [next] | [standalone]


#13188

FromSzabolcs Horvát <szhorvat@gmail.com>
Date2013-01-18 05:49 +0000
Message-ID<kdanq2$3dc$1@smc.vnet.net>
In reply to#13160
As I understood, this is what the OP was asking for.  It will work with any
export format, but of course it is true that with some formats it doesn't
make sense.  Appending two PDFs will just breaks them.

With some formats, e.g. CSV, it can be useful.


On 17 January 2013 10:14, Murray Eisenberg <murray@math.umass.edu> wrote:

> But surely appending like that won't work for many export formats. E.g., I
> hesitate to think what it might do to a PDF export.
>
> On Jan 16, 2013, at 11:16 PM, Szabolcs <szhorvat@gmail.com> wrote:
>
> > Hello Maarten,
> >
> > In fact there is a simple way to make Export append rather than
> overwrite.  Please see here:
> >
> > http://mathematica.stackexchange.com/a/2228/12
> >
> > You just need to use a stream in place of the file name:
> >
> > file = OpenAppend["out.txt"]
> >
> > Export[file, data, "CSV"];
> > WriteString[file, "\n"];
> >
> > Close[file]
> >
> > On Wednesday, 16 January 2013 01:38:58 UTC-5, Maarten van der Burgt
>  wrote:
> >> Dear Alexei,
> >>
> >>
> >>
> >> Thanks for your help. Hope the Wolfram folks are reading this as well.
> >>
> >> Something simple like this should really be an option in the function
> >>
> >> Export.
> >>
> >>
> >>
> >> Meanwhile I found back something similar for XLS files in my knowledge
> >>
> >> base:
> >>
> >>
> >>
> >> XLAppend[oldfile_, newfile_, newdata_] :=  Module[
> >>
> >>
> >>
> >> {sheets, olddata, completedata},
> >>
> >>
> >>
> >>  sheets = Import[oldfile, "Sheets"];
> >>
> >>
> >>
> >>  olddata = {#, Import[oldfile, {"Sheets", #}]} & /@ sheets;
> >>
> >>
> >>
> >>  completedata = Join[olddata, newdata];
> >>
> >>
> >>
> >> Export[newfile, Rule @@@ completedata]
> >>
> >>
> >>
> >> ]
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> Best regards,
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> Maarten
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> Maarten van der Burgt
> >>
> >>
> >>
> >> Product Engineering  - ICOS Division
> >>
> >>
> >>
> >> ________________________________
> >>
> >>
> >>
> >> KLA-Tencor | ICOS Division
> >>
> >> Tel: +32 16 398220 | Direct: +32 16 398263 | Fax: +32 16 400067
> >>
> >>
> >>
> >> KLA-TENCOR (Belgium) - Haasrode Research Park 1112 - Esperantolaan 8 -
> >>
> >> B-3001 Leuven - BELGIUM
> >>
> >>
> >>
> >> Mail: maarten.vanderburgt@kla-tencor.com
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> From: Alexei Boulbitch [mailto:Alexei.Boulbitch@iee.lu]
> >>
> >> Sent: maandag 14 januari 2013 10:22
> >>
> >> Cc: Maarten van der Burgt
> >>
> >> Subject: Re: Export with append??
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> Hallo,
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> With a command like
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> Export["myfile.dat", results, "List" ]
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> is there a way to append the results to an existing myfile.dat, rather
> >>
> >>
> >>
> >> than creating or overwriting an existing file?
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> thanks for your help,
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> Maarten
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> Hi, Maarten,
> >>
> >>
> >>
> >> A simple workaround is to import your file, append a new file to it and
> >>
> >> then - to export the combined list. Assume that your mathematica
> >>
> >> notebook entitled "trialImportExport.nb"  is situated in the same folder
> >>
> >> as the already existing list entitled "myfile.dat".
> >>
> >>
> >>
> >> To be precise I generated the file myfile.dat with the list:
> >>
> >>
> >>
> >> {25, 36, 49}
> >>
> >>
> >>
> >> in it. Assume further that I want to append the list
> >>
> >>
> >>
> >> {a,b,c}
> >>
> >>
> >>
> >> to it. Then the code
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> lst1=Import[NotebookDirectory[]<>"myfile.dat"]//Flatten;
> >>
> >>
> >>
> >> lst2={a,b,c};
> >>
> >>
> >>
> >> lst3=Append[lst1,lst2]//Flatten;
> >>
> >>
> >>
> >> Export[NotebookDirectory[]<>"myfileNew.dat",lst3]
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> Does the job. The output cell below:
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> D:\Documents and Settings\ABo\My
> >>
> >> Documents\Works\Mathematica_works\Examples\TrialFiles\myfileNew.dat
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> shows that the file has been successfully exported.
> >>
> >>
> >>
> >> I intentionally gave the resulting file a new name, "myfileNew.dat", to
> >>
> >> check the result, but the old name can also be given to it.
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> Have fun, Alexei
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> Alexei BOULBITCH, Dr., habil.
> >>
> >>
> >>
> >> IEE S.A.
> >>
> >>
> >>
> >> ZAE Weiergewan,
> >>
> >>
> >>
> >> 11, rue Edmond Reuter,
> >>
> >>
> >>
> >> L-5326 Contern, LUXEMBOURG
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> Office phone :  +352-2454-2566
> >>
> >>
> >>
> >> Office fax:       +352-2454-3566
> >>
> >>
> >>
> >> mobile phone:  +49 151 52 40 66 44
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> e-mail: alexei.boulbitch@iee.lu
>
> ---
> Murray Eisenberg                                    murray@math.umass.edu
> Mathematics & Statistics Dept.
> Lederle Graduate Research Tower            phone 413 549-1020 (H)
> University of Massachusetts                               413 545-2838 (W)
> 710 North Pleasant Street                         fax   413 545-1801
> Amherst, MA 01003-9305
>
>
>
>
>
>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web