in tcl, how do I replace a line in a file?

前端 未结 5 1322
执念已碎
执念已碎 2021-01-01 03:55

let\'s say I opened a file, then parsed it into lines. Then I use a loop:

foreach line $lines {}

inside the loop, for some lines, I want to

5条回答
  •  伪装坚强ぢ
    2021-01-01 04:41

    set fileID [open "lineremove.txt" r] 
    set temp [open "temp.txt" w+] 
    while {[eof $fileID] != 1} { 
        gets $fileID lineInfo 
        regsub -all "delted information type here" $lineInfo "" lineInfo 
        puts $temp $lineInfo 
    } 
    file delete -force lineremove.txt 
    file rename -force temp.txt lineremove.txt 
    

提交回复
热议问题