# Do, Write Through

Using:

Do[Write[OUTFILE, #] & @@ Through[{(#) &, Sin[#] &, Cos[#] &}[n]], {n, {1, 2, 3, 4}}]


results with file content:

{1, Sin[1], Cos[1]}
{2, Sin[2], Cos[2]}
{3, Sin[3], Cos[3]}
{4, Sin[4], Cos[4]}


But I would like to have:

1,Sin[1],Cos[1]
2,Sin[2],Cos[2]
3,Sin[3],Cos[3]
4,Sin[4],Cos[4]


And, additionally, when writing file paths, they are quoted. How to write path stripped of quotes?

• Something like ExportString[RandomReal[1, {3, 4}], "CSV"]? – Kuba Nov 13 '14 at 20:14

If you want to write one line at a time, use ExportString on each line, then WriteString:
 Do[

Generally you should save up the output data and Export it all at once though. Only write in the loop like that if for example the loop time is very long and you need the output always up to date.