# Writedlm - adding a blank line every n lines

**URL:** <https://discourse.julialang.org/t/writedlm-adding-a-blank-line-every-n-lines/36111>\
**Category:** General Usage\
**Created:** [March 17, 2020, 8:41pm UTC](https://discourse.julialang.org/t/writedlm-adding-a-blank-line-every-n-lines/36111 "2020-03-17T20:41:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![razvangheorghe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/razvangheorghe/32/12436_2.png) [@razvangheorghe](https://discourse.julialang.org/u/razvangheorghe)\
**Post date:** [March 17, 2020, 8:41pm UTC](https://discourse.julialang.org/t/writedlm-adding-a-blank-line-every-n-lines/36111/1 "2020-03-17T20:41:14Z")

</div>

Hi,

I have three columns of numbers. x and y are coordinates and z is the value at x and y. I’m currently saving them to files like this:

```julia
open(path, "w") do io
    writedlm(io, [x y z])
end

```

I’m trying to splot as a pm3d map in gnuplot which needs a blank line for every change in the x value (see [here](https://askubuntu.com/questions/900501/i-cant-splot-with-pm3d-map-my-data-file-gnuplot)).

I want to add blank lines and I assume it’s easier since my x value only changes every n lines throughout. What’s the most convenient way to do this?

Thanks

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [March 17, 2020, 8:57pm UTC](https://discourse.julialang.org/t/writedlm-adding-a-blank-line-every-n-lines/36111/2 "2020-03-17T20:57:00Z")

</div>

You may be interested in [Gaston](https://mbaz.github.io/Gaston.jl/v0.10.0/), a plotting package based on gnuplot.

I also use `writedlm` to output data for gnuplot. The relevant code starts [here](https://github.com/mbaz/Gaston.jl/blob/1178c6d7086a283d45d3da9c1dbb0f8fcd977d1b/src/gaston_llplot.jl#L144).

---

<div class="post-metadata">

**Author:** ![razvangheorghe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/razvangheorghe/32/12436_2.png) [@razvangheorghe](https://discourse.julialang.org/u/razvangheorghe)\
**Post date:** [March 17, 2020, 9:14pm UTC](https://discourse.julialang.org/t/writedlm-adding-a-blank-line-every-n-lines/36111/3 "2020-03-17T21:14:20Z")

</div>

Sorry, this is not very flexible at the moment. Someone else wants to use gnuplot in a linux command line. Thanks for the help though. I’ll have a look.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [March 18, 2020, 7:21am UTC](https://discourse.julialang.org/t/writedlm-adding-a-blank-line-every-n-lines/36111/4 "2020-03-18T07:21:45Z")

</div>

```julia
open(path, "w") do io
	last=x[firstindex(x)]
	for index in eachindex(x)
		if last != x[index]
			writedlm(io," ")
		end
		writedlm(io, [x[index] y[index] z[index]])
		last=x[index]
	end
end

```

I interpret “convenient” as to be equal to easy or straight forward for today.
