1
$\begingroup$

I have the following list:

list = {1,2,3,4,5}

Now I would like to export the list to a text file such that the numbers are all on one line separated by a tab:

1 2 3 4 5

When I do:

Export["list.txt",list] 

I get:

1

2

3

4

5

I am wondering if it is possible to get the desired output ?

| improve this question | | | | |
$\endgroup$
  • $\begingroup$ Export["list.txt", list, "Table", "LineSeparators" -> " "]? $\endgroup$ – Sjoerd Smit Sep 25 '19 at 9:26
  • $\begingroup$ @Sjoerd Smit Yes, that's exactly what I was looking for. Thanks a lot. You can post it as an answer, then I can accept it. :) $\endgroup$ – henry Sep 25 '19 at 9:31
2
$\begingroup$

The following should work:

Export["list.txt", list, "Table", "LineSeparators" -> " "]

The "Table" format also supports a "FieldSeparators" option to separate columns in 2D data, should you need it.

| improve this answer | | | | |
$\endgroup$
1
$\begingroup$

My take on it:

list = {{1, 2, 3, 4, 5}}

Export["list.txt", list, "TSV"]

In TSV values in the same row are delimited by tab and values in the same column are delimited by newline.

| improve this answer | | | | |
$\endgroup$

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.