| View previous topic :: View next topic |
| Author |
Message |
DarkGhost Voice
Joined: 15 Jan 2007 Posts: 6
|
Posted: Mon Jan 15, 2007 9:03 pm Post subject: How to overwrite/delete a line from .txt |
|
|
| Hello I am making a login script with in a file.txt I have "username host password access online|offline" and when someone logs in i want to make the offline to online or when someone wants to change there password I want to change password but I am unsure how to do this please help thanks. |
|
| Back to top |
|
 |
DarkGhost Voice
Joined: 15 Jan 2007 Posts: 6
|
Posted: Tue Jan 16, 2007 7:44 am Post subject: |
|
|
Hello, I have seen alot of people look at this if you cant overwrite/delete lines atleast tell me  |
|
| Back to top |
|
 |
r0t3n Owner
Joined: 31 May 2005 Posts: 507 Location: UK
|
Posted: Tue Jan 16, 2007 9:20 am Post subject: |
|
|
A quick example to help you out:
| Code: | 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 |
_________________ r0t3n @ #r0t3n @ Quakenet |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Jan 16, 2007 10:52 am Post subject: |
|
|
| DarkGhost wrote: | Hello, I have seen alot of people look at this if you cant overwrite/delete lines atleast tell me  |
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.) |
|
| Back to top |
|
 |
DarkGhost Voice
Joined: 15 Jan 2007 Posts: 6
|
Posted: Tue Jan 16, 2007 7:13 pm Post subject: |
|
|
Thanks it works great only problem is it doesnt delete the line its editing  |
|
| Back to top |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Wed Jan 17, 2007 6:55 am Post subject: |
|
|
| DarkGhost wrote: | Thanks it works great only problem is it doesnt delete the line its editing  |
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. _________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
DragnLord Owner

Joined: 24 Jan 2004 Posts: 711 Location: C'ville, Virginia, USA
|
Posted: Wed Jan 17, 2007 11:32 am Post subject: login to what? |
|
|
What type of login are you trying to create this for?
If this is for checking if someone is logged into the bot, it would be easier to check with a script using the dcc command "whom".
Changing password for eggdrop users is easiest done by using private message to the bot using "pass <oldpass> <newpass>"
(example: /msg botnick pass currentpass newpass)
If this is for some sort of website portal, then you will need a much more complicated approach. |
|
| Back to top |
|
 |
DarkGhost Voice
Joined: 15 Jan 2007 Posts: 6
|
Posted: Wed Jan 17, 2007 4:11 pm Post subject: |
|
|
| user wrote: | | DarkGhost wrote: | Thanks it works great only problem is it doesnt delete the line its editing  |
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. |
lol your so SMART! i had to change some stuff around but here
| Code: |
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"
}
|
Oh and by the way i got it to work perfectly thanks. |
|
| Back to top |
|
 |
|