0
$\begingroup$

I want to Export a list of lists in Table format with \t or blank as delimiter. Unfortunatelly Mathematica 4.0 does not have the FieldSeparator option aviable.

Is there still a way to program this without the FieldSeparator command?

Example:

    list=Table[Random[Real,90],{2}]&/@Range[6];

I have searched this site and adapted an answer to a similar question:

    Export["list.txt",({list[[All,1]],90-list[[All,2]]}//Transpose)/.x_?NumberQ:>ToString[NumberForm[x,NumberPoint->","]],"Table"];

Additionally to changing the NumberPoint I want the entries to have only a single delimiter character between the columns list[[All,1]] and 90-list[[All,2]] in every line, i.e. a single spacebar or tab, to be able to import the data with another program.

The standard Export command however uses 4 times blank after padding every entry with blanks, which is an issue.

Thanks in advance and sorry for my lack of knowledge in formatting my questions properly!

$\endgroup$
1
  • $\begingroup$ We need to provide an answer that runs on Mathematica version 4.0? I imagine you could use Write to do what you want. $\endgroup$
    – Jason B.
    Mar 1, 2018 at 17:35

1 Answer 1

2
$\begingroup$

I think this should work with Mathematica version 4 :

list=Table[Random[Real,90],{2}]&/@Range[6];

myRiffleForMma4[l_List,elt_String]:=Insert[l,elt,List /@ Range[2,Length[l]]]

Export["test00.txt",
       StringJoin[
           myRiffleForMma4[
              StringJoin[myRiffleForMma4[#," "]]& /@ Map[ToString,list,{2}],
              "|"]
               ],
       "String"]  

Mathematica 11.0 gives :

42.5872 74.261|86.0062 6.89626|75.0751 61.5735|44.216 83.7371|36.7864 2.49404|63.8472 36.3133

If you move to a newer Mathematica, you can replace myRiffleForMa4[] by the built-in function Riffle[] (introduced in version 6).

$\endgroup$
2
  • $\begingroup$ I may forget something that doesn't work with Mathematica 4. Please advice me. $\endgroup$
    – andre314
    Mar 1, 2018 at 17:42
  • $\begingroup$ Hey @andre, thank you for your answer! Unfortunatelly, Export doesn't recognize "String" as a format in Mma4... however your code works pretty good with "Table" instead! Thanks alot! $\endgroup$
    – ANewb
    Mar 6, 2018 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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