I Have a list in a file called requests.txt which looks like this:
#Test
#Test2
#Test3
#Test4
#Test5
#Test6
(etc)
When i use a !trigger from a channel to remove a certain word from the file it deletes every line in the file instead of the match and here is what i have:
set fname "files/requests.txt"
set fp [open $fname "w+"]
set data [read -nonewline $fp]
set lines [split $data "\n"]
while {[set i [lsearch -glob $lines $text]]>-1} {
set lines [lreplace $lines $i $i]
}
close $fp
set fname "files/requests.txt"
set fp [open $fname "r"]
set data [read -nonewline $fp]
set lines [split $data "\n"]=
close $fp
set fp [open $fname "w"]
while {[set i [lsearch -glob $lines $text]]>-1} {
set lines [lreplace $lines $i $i]
}
close $fp
now got that but it still deletes all the lines. not just the one that is stated in $text
set fname "files/requests.txt"
set fp [open $fname "r"]
set data [read -nonewline $fp]
set lines [split $data "\n"]
close $fp
while {[set i [lsearch -glob $lines $text]]>-1} {
set lines [lreplace $lines $i $i]
}
set fp [open $fname "w"]
puts $fp [join $lines "\n"]
close $fp
seems to be ok now? but does the code look ok? or could it be tidied up a bit?