I have some problems exporting Table data into ASCII files preserving column alignment.
By example (under Mathematica v11.2 + Linux):
I generate a random table with 2 columns
t = Table[StringJoin[RandomChoice[CharacterRange["A", "Z"], RandomInteger[{1,10}]]], 10, 2];
UOTKRPUOVS PZFON WQSMI FVAGV SGOZQJP KYWTGIBGF B QEKUEFN EKPU WVIKS CHXJBPGXA BAMYNNG FZFXXWZ TQUYN A K ICZFK MDLKDKIGTD NLXH WVAWTL
I export it into a Text file with this command:
Export["test.txt", t, "Table"]
However if I look the exported file (from terminal):
cat test.txt
I get:
UOTKRPUOVS PZFON WQSMI FVAGV SGOZQJP KYWTGIBGF B QEKUEFN EKPU WVIKS CHXJBPGXA BAMYNNG FZFXXWZ TQUYN A K ICZFK MDLKDKIGTD NLXH WVAWTL
-> column alignment is completely lost.
Fix?:
The only way I have found so far to fix this issue is to export the table using:
Export["test.txt", StringReplace[ToString[Grid[t]], "\n\n" -> "\n"], "Text"]
Now,
cat test.txt
gives me back the right formatting:
UOTKRPUOVS PZFON WQSMI FVAGV SGOZQJP KYWTGIBGF B QEKUEFN EKPU WVIKS CHXJBPGXA BAMYNNG FZFXXWZ TQUYN A K ICZFK MDLKDKIGTD NLXH W
This works but that seems a very awkward solution for such a basic problem...
Any better idea?
Note: maybe the StringReplace[..., "\n\n" -> "\n"]
step is useless under Windows, but I had not the opportunity to check that.