egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to overwrite/delete a line from .txt

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
DarkGhost
Voice


Joined: 15 Jan 2007
Posts: 6

PostPosted: Mon Jan 15, 2007 9:03 pm    Post subject: How to overwrite/delete a line from .txt Reply with quote

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
View user's profile Send private message
DarkGhost
Voice


Joined: 15 Jan 2007
Posts: 6

PostPosted: Tue Jan 16, 2007 7:44 am    Post subject: Reply with quote

Hello, I have seen alot of people look at this if you cant overwrite/delete lines atleast tell me Smile
Back to top
View user's profile Send private message
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Tue Jan 16, 2007 9:20 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Tue Jan 16, 2007 10:52 am    Post subject: Reply with quote

DarkGhost wrote:
Hello, I have seen alot of people look at this if you cant overwrite/delete lines atleast tell me Smile

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
View user's profile Send private message
DarkGhost
Voice


Joined: 15 Jan 2007
Posts: 6

PostPosted: Tue Jan 16, 2007 7:13 pm    Post subject: Reply with quote

Thanks it works great only problem is it doesnt delete the line its editing Sad
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Wed Jan 17, 2007 6:55 am    Post subject: Reply with quote

DarkGhost wrote:
Thanks it works great only problem is it doesnt delete the line its editing Sad

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
View user's profile Send private message
DragnLord
Owner


Joined: 24 Jan 2004
Posts: 711
Location: C'ville, Virginia, USA

PostPosted: Wed Jan 17, 2007 11:32 am    Post subject: login to what? Reply with quote

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
View user's profile Send private message
DarkGhost
Voice


Joined: 15 Jan 2007
Posts: 6

PostPosted: Wed Jan 17, 2007 4:11 pm    Post subject: Reply with quote

user wrote:
DarkGhost wrote:
Thanks it works great only problem is it doesnt delete the line its editing Sad

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber