# Add empty lines to a file when exporting data [duplicate]

Let's say I have a table of numerical data with three columns as follows:

X1 Y1 Z1
X1 Y2 Z2
.
.
.
X2 Y1 Z1
X2 Y2 Z2
.
.
.


Is it possible to export this table in a file such that after each column with constant x there is a blank line?

Like so:

X1 Y1 Z1
X1 Y2 Z2
.
.
.
(*blank line*)
X2 Y1 Z1
X2 Y2 Z2
.
.
.
(*blank line*)
X3 Y1 Z1
X3 Y2 Z2
.
.
.


This is a bit strange but I am trying to use gnuplot to plot contour lines and apparently this is how you have to have the data organised.

Edit: I should have added a working example with how my data is generated. Here is a simple table of how my data looks like:

Table[{x,y,x+y},{x,0,10},{y,-10,0}]


Now what i want is to export this to a file such that the data is separated in blocks of constant x. So for x=0 we get the fist block of 11 entries then a blank like then the next block with x=1 and so on.

• It is not obvious from your post how your data is actually structured in Mathematica. Could you edit the post to show a sample of your data as a valid Mathematica expression? – m_goldberg Apr 14 '17 at 16:33

It might be simplest to use low level file i/o for this:

x1 = RandomReal[{-1, 1}, {10, 3}]
x2 = RandomReal[{-1, 1}, {10, 3}]
f = OpenWrite["test.dat"];
WriteLine[f, ExportString[x1, "Table"]];
WriteLine[f, ""];
WriteLine[f, ExportString[x2, "Table"]];
Close[f]


or with Export its like this:

Export["test.dat", Flatten[Riffle[{x1, x2}, {{""}}], 1] , "Table"]

• This was spot on! Actually it worked like this: For the table in my original question I exported: Export["test.dat",Flatten[Riffle[Table[{x,y,x+y},{x,0,10},{y,-10,0}],{{" "}}],1]]. This produced the desired output! – lucian Apr 14 '17 at 20:44