With the code for reading a whole file:
Code: Select all
set fname "textfile.txt"
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
How to solve that?
Code: Select all
set fname "textfile.txt"
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
Code: Select all
foreach line [split $data \n] {
putcmdlog "line '$line'"
}
Code: Select all
# read data in
if {![file exists $quotefile]} {return "No quotes available."}
set quotelines ""
set inqfile [open $quotefile r]
set quotetemp [split [read $inqfile] \n]
catch {close $inqfile}
foreach line $quotetemp {
if {$line != ""} {
lappend quotelines $line
}
}
Code: Select all
# write data out
set quotewrite [open $quotefile w]
foreach line $quotelines {
set line [string trim $line]
if {$line != ""} {
puts $quotewrite $line
}
}
catch {close $quotewrite}