5
$\begingroup$

I have a list of points (e.g. {1.2,0.4}) which I export to a file using

Export[fileName, list];

I want to add a line before the end of file. For instance instead of ending the file with

1.236677 4.64567567
1.236677 4.64567567
1.236676 4.64567567

ending like

1.236677 4.64567567
1.236677 4.64567567
1.236676 4.64567567
# a blank line here

I tried appending {}, {,}, "" to the list, but none of them added a blank line.

I need this because xmgrace is not parsing the last line of the exported mathematica file: it expects a blank line before the End of File.


EDIT: As pointed out in the comments by Kuba and Pinguin Dirk, appending "" works on Windows XP (and probably others.) I'm using OS X.

$\endgroup$
  • 1
    $\begingroup$ maybe something like: Export["foo.txt", Append[list, ""]]? $\endgroup$ – Pinguin Dirk Sep 11 '13 at 9:41
  • $\begingroup$ I already tried that but it doesn't work. If I use " ", it prints a new line with a white space in it. $\endgroup$ – Jorge Leitao Sep 11 '13 at 10:10
  • $\begingroup$ @J.C.Leitão What OS are you working on? Pinguin Dirk's solution works on WinXP. $\endgroup$ – Kuba Sep 11 '13 at 10:22
  • 1
    $\begingroup$ If all else fails: file=OpenAppend["file"]; Write["\n"]; Close[file] $\endgroup$ – C. E. Sep 11 '13 at 10:50
  • 1
    $\begingroup$ @cormullion, yep, OS X here too, and I too tried "\n". What file type are you exporting to? $\endgroup$ – Pinguin Dirk Sep 11 '13 at 12:20
4
$\begingroup$

Here, on my OSX the following works

Export["tmp/foo.txt", Append[Range[10], "\n"]]

Mathematica graphics

$\endgroup$
1
$\begingroup$

Try

Export[fileName, Append[list, ""], "Table"]

This should be OS-independent although I cannot check this under OS X.

$\endgroup$
  • $\begingroup$ Doesn't work with OSX. At least on my 9.0.1 with OSX 10.8.4 $\endgroup$ – halirutan Sep 11 '13 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.