Tag Info

New answers tagged

0

Being fairly annoyed that mathematica can't do this straightforward thing..here is a solution using an external python script: Export["test.txt", Join[{StringJoin[Join[{"*"}, ConstantArray[" ", {80}], {"*"}]]}, RandomInteger[100, {3, 20}], {"end of file\n"}], "Table"] FilePrint["test.txt"] overwrite[file_, off_, string_] := Run[ ...


2

Low-level file operators like Write won't work here because OutputStreams (such as you get with OpenWrite and OpenAppend) can't have their StreamPosition set before the end of the file. In general overwriting characters in an existing file isn't terribly trivial; you can use c-functions likefile_ptr = fopen(file, "rb+") to do this, but you're overwriting ...


3

In this case, it is advisable to use the Export command: Export["test", data, "Table"] Leads to: Alternative one can use TableSpacing i.e. manipulate space between rows or columns, OutputForm[TableForm[data, TableSpacing -> {0, 0}]] >> "test" this leads to; Edit One can control Accuracy by: data1 = SetAccuracy[RandomReal[{-1, 1}, {3, ...


4

One workaround I found is this: getRand[] := AbortProtect@Module[{stream, res}, stream = OpenRead["!head -c 4 /dev/random", BinaryFormat -> True]; res = BinaryRead[stream, "UnsignedInteger32"]; Close[stream]; res ] Tested on OS X and Linux.


5

A simple way to read the last line of a file uses ReadList to get all lines from the file and then returns the last element of the list: lastLine[file_] := ReadList[file, String] // Last This code ignores the possibility of an empty file. If we care about such an eventuality, we can deal with it using a bit more logic: lastLine[file_] := ReadList[file, ...



Top 50 recent answers are included