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 

Deleting a line from a text file.

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Justdabomb2
Voice


Joined: 29 Sep 2006
Posts: 37
Location: United States of America

PostPosted: Mon Oct 02, 2006 9:20 pm    Post subject: Deleting a line from a text file. Reply with quote

Could someone help create me a proc that will delete the line

"[JuanCarlos] <juancarlos> <3780-2292-1521>"

from the lines below.

[Chaoszer14] <chaoszero14> <3350-8023-6356>
[Jjoiu] <jjoiu> <0687-8131-8871>
[JuanCarlos] <juancarlos> <3780-2292-5121>
[Lostfan2420] <lostfan2420> <4639-3128-6539>
[Shade] <shade> <5412-2685-7596>

------------

I am having quite a bit of trouble figuring out how to a remove a specified line from a text file. And if you can, could you make so that the person could only remove the line "[JuanCarlos] <juancarlos> <3780-2292-1521>" if there name was juancarlos.

When I tried to make a proc to do this myself, it ended up deleting my whole txt file. The code I used is below. Maybe I did something wrong in my code, or maybe I just need a new code in general. (everytime it would say user not found when I typed !delmpht juancarlos, and then I checked the user to file to clarify, and the whole file was erased.)

Code:

proc deleteuser {nick uhost hand chan arg} {
  global mphtfile
  if {$arg != ""} {
    set gamer [lindex [split $arg] 0]
    set fd [open $::mphtfile r+]
    while {![eof $fd]} {
      lappend list [gets $fd]
    }
    close $fd
    set fd [open $::mphtfile w+]
    if {[set le [lsearch -exact $list $gamer]] != -1} {
      puts -nonewline $fd [join [lreplace $list $le $le] \n]
      } else {
      putquick "PRIVMSG $chan :That user was not found."
    }
    close $fd
  }
}


Thank you!
_________________
Yeah!
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
rosc2112
Revered One


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

PostPosted: Mon Oct 02, 2006 11:54 pm    Post subject: Reply with quote

Code:

proc deleteuser {nick uhost hand chan arg} {
  global mphtfile
  if {$arg != ""} {
         set arg [string tolower $arg]
         set gamer [lindex [split $arg] 0]
         set nick [string tolower $nick]
         if {$nick == $gamer} {
              set fd [open $mphtfile r]
              while {![eof $fd]} {
                     lappend list [gets $fd]
              }
              close $fd
              set le [lsearch -exact $list $gamer]
              if {$le != -1} {
                       lreplace $list $le $le
                       set fd [open $mphtfile w]
                       foreach line $list {
                             if {$line != ""} {
                                   puts $fd [join $line]
                             }
                       }
                       close $fd
              } else {
                         putquick "PRIVMSG $chan :That user was not found."
              }
          } else {
                       putquick "PRIVMSG $nick :That's not your entry so I won't delete it"
          }
  }
}

Something like that.
Back to top
View user's profile Send private message
rosc2112
Revered One


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

PostPosted: Mon Oct 02, 2006 11:58 pm    Post subject: Reply with quote

Actually, I think you'd have to use lsearch -glob unless you use lindex and split to get the exact name for $gamer from the file first. I answered a post (now in the script request forum) that might be helpful, to show how to read/write/parse text files:
http://forum.egghelp.org/viewtopic.php?p=66839#66839
Back to top
View user's profile Send private message
Justdabomb2
Voice


Joined: 29 Sep 2006
Posts: 37
Location: United States of America

PostPosted: Tue Oct 03, 2006 3:44 pm    Post subject: hmm Reply with quote

I tested the script you gave ^^^^

and this is what ir said

Quote:
[15:43] <~Justdabomb2> !delmpht justdabomb2
[15:43] <JustdaBot> That user was not found.
[15:43] <~Justdabomb2> !delmpht juancarlos
[15:43] <JustdaBot> That's not your entry so I won't delete it


So the nick thing works, but it still did not delete the line. It didn't delete anything. Any suggestions?
_________________
Yeah!
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
rosc2112
Revered One


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

PostPosted: Tue Oct 03, 2006 5:43 pm    Post subject: Reply with quote

read my last reply about glob.
Back to top
View user's profile Send private message
rosc2112
Revered One


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

PostPosted: Tue Oct 03, 2006 5:45 pm    Post subject: Reply with quote

Actually, you should not be posting scripts to the egghelp tcl archive until you have a clue what you're doing. Shame that files can't come with a big fat WARNING about absolutely clueless people and the potential for deleting your entire hard drive.


And no, I won't write the script for you, when you'll just post it as if you had written it.
Back to top
View user's profile Send private message
Justdabomb2
Voice


Joined: 29 Sep 2006
Posts: 37
Location: United States of America

PostPosted: Tue Oct 03, 2006 8:28 pm    Post subject: ... wtf Reply with quote

Yeah, I have no clue what I am doing *sarcasm end*... I am still learning for one. And you aren't too good yourself... There are a few things I don't know okay... big deal.
_________________
Yeah!
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Justdabomb2
Voice


Joined: 29 Sep 2006
Posts: 37
Location: United States of America

PostPosted: Tue Oct 03, 2006 8:43 pm    Post subject: ... Reply with quote

and if I recall correctly, I never asked you to completely write me a script, I had something, but it messed up, so I asked for help.
_________________
Yeah!
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
rosc2112
Revered One


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

PostPosted: Tue Oct 03, 2006 10:23 pm    Post subject: Reply with quote

I gave you help, you haven't utilized it. Whether I'm good or not is irrelevent. If you're not looking for a full script, why are you posting in the request forum?
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 -> Script Requests 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