This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Deleting a line from a text file.

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
J
Justdabomb2
Voice
Posts: 37
Joined: Fri Sep 29, 2006 7:16 pm
Location: United States of America

Deleting a line from a text file.

Post by Justdabomb2 »

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: Select all

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!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Code: Select all

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.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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
J
Justdabomb2
Voice
Posts: 37
Joined: Fri Sep 29, 2006 7:16 pm
Location: United States of America

hmm

Post by Justdabomb2 »

I tested the script you gave ^^^^

and this is what ir said
[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!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

read my last reply about glob.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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.
J
Justdabomb2
Voice
Posts: 37
Joined: Fri Sep 29, 2006 7:16 pm
Location: United States of America

... wtf

Post by Justdabomb2 »

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!
J
Justdabomb2
Voice
Posts: 37
Joined: Fri Sep 29, 2006 7:16 pm
Location: United States of America

...

Post by Justdabomb2 »

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!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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?
Post Reply