Q: How do I write file.CSV in tcl/tk scripting

451 Views Asked by At

I have 3 strings: string1 string2 string3

I want to export file.csv

I try to use

echo "string1,string2,string3" >> file.csv

but its not working

1

There are 1 best solutions below

0
On

File handling in Tcl takes a few more commands (but is more efficient when you're writing many lines as a result):

set f [open file.csv w]
puts $f "string1,string2,string3"
close $f

The w is critical: it says to open the file for writing.


If you're doing a lot of CSV writing, use the package in Tcllib for the job. It handles complicated edge cases for you.