Code: Select all
set file [open file.txt w+]
foreach line [split [read -nonewline $file] \n] {
if {$line == ""} { return }
if {[string match -nocase "USERNAME" [lindex [split $line] 0]]} {
# To remove the line from file
# return
# To edit the line data
# regexp -nocase {(.+)\s(.+)\s(.+)\s(.+)\s(.+)} $line -> username host password access status
# To change the password use:
# set password "NEWPASS"
# To change online/offline status use:
# set status "ONLINE or OFFLINE"
# Write the modified data back to file
# puts $file "$username $host $password $access $status"
} else {
# We don't need to delete/modify this line, write the line back to file
puts $file "$line"
}
}
close $file
It's probably one of those FAQ questions, and you could've found the answer yourself by searching the forum (I know I've written quite a few examples of this and didn't feel like doing it again.)DarkGhost wrote:Hello, I have seen alot of people look at this if you cant overwrite/delete lines atleast tell me
what "it"? Tosser's code would not work as it will truncate the file before attempting to read from it, so I'm guessing you made something yourself based on what you read in the faq...show us your code.DarkGhost wrote:Thanks it works great only problem is it doesnt delete the line its editing
lol your so SMART! i had to change some stuff around but hereuser wrote:what "it"? Tosser's code would not work as it will truncate the file before attempting to read from it, so I'm guessing you made something yourself based on what you read in the faq...show us your code.DarkGhost wrote:Thanks it works great only problem is it doesnt delete the line its editing
Code: Select all
putserv "PRIVMSG $nick :You are now logged in to $userName"
set file [open test.txt r+]
foreach line [split [read -nonewline $file] \n] {
if {$line == ""} { return }
if {[string match -nocase "$userName" [lindex [split $line] 0]]} {
regexp -nocase {(.+)\s(.+)\s(.+)\s(.+)\s(.+)} $line -> username host password access
set status "ONLINE"
close $file
set file [open test.txt w+]
puts $file "$username $host $password $access $status"
} else {
puts $file "$line"
}