如何将 Tcl 中多行的输出重定向到一个文件?
How do I redirect the output on multiple lines in the Tcl to a file?
如何将 Tcl 中多行的 'variable' 的输出重定向到一个文件。例如:
假设我有包含以下行的文件:
Linha
Linha
Linha
Linha
等等...
替换:
Line
Line
Line
Line
等等。
问题的原因是在将输出重定向到新文件时,我只收到了输出的最后一行。前几行在哪里???
这是我目前正在使用的程序:
# Open File
set open [open /tmp/linhas.txt]
# Read File
set read [read $open]
# Break File Line at the End (Space)
set line [split $read "\n"]
# Close File
close $open
# Going through a loop to capture only the necessary replacement
for {set i 1} {$i < 5} {incr i} {
set out [string map -nocase { {Linha} {Line} } [lindex $line $i]]
}
# Create New File
set fp [open /tmp/outputFile.txt w]
# Insert output on the New File
puts $fp $out
# Close File New
close $fp
# View File New
exec aterm -e vi /tmp/outputFile.txt
通过glenn jackman的评论解决了问题,所以是这样的:
# Open File
set open [open /tmp/linhas.txt]
# Read File
set read [read $open]
# Break File Line at the End (Space)
set line [split $read "\n"]
# Close File
close $open
# Create New File
set fp [open /tmp/outputFile.txt w]
# Going through a loop to capture only the necessary replacement
for {set i 1} {$i < 5} {incr i} {
set out [string map -nocase { {Linha} {Line} } [lindex $line $i]]
# Insert output on the New File
puts $fp $out
}
# Close File New
close $fp
# View File New
exec aterm -e vi /tmp/outputFile.txt
如何将 Tcl 中多行的 'variable' 的输出重定向到一个文件。例如:
假设我有包含以下行的文件:
Linha Linha Linha Linha
等等...
替换:
Line Line Line Line
等等。
问题的原因是在将输出重定向到新文件时,我只收到了输出的最后一行。前几行在哪里???
这是我目前正在使用的程序:
# Open File
set open [open /tmp/linhas.txt]
# Read File
set read [read $open]
# Break File Line at the End (Space)
set line [split $read "\n"]
# Close File
close $open
# Going through a loop to capture only the necessary replacement
for {set i 1} {$i < 5} {incr i} {
set out [string map -nocase { {Linha} {Line} } [lindex $line $i]]
}
# Create New File
set fp [open /tmp/outputFile.txt w]
# Insert output on the New File
puts $fp $out
# Close File New
close $fp
# View File New
exec aterm -e vi /tmp/outputFile.txt
通过glenn jackman的评论解决了问题,所以是这样的:
# Open File
set open [open /tmp/linhas.txt]
# Read File
set read [read $open]
# Break File Line at the End (Space)
set line [split $read "\n"]
# Close File
close $open
# Create New File
set fp [open /tmp/outputFile.txt w]
# Going through a loop to capture only the necessary replacement
for {set i 1} {$i < 5} {incr i} {
set out [string map -nocase { {Linha} {Line} } [lindex $line $i]]
# Insert output on the New File
puts $fp $out
}
# Close File New
close $fp
# View File New
exec aterm -e vi /tmp/outputFile.txt