| View previous topic :: View next topic |
| Author |
Message |
Justdabomb2 Voice
Joined: 29 Sep 2006 Posts: 37 Location: United States of America
|
Posted: Mon Oct 02, 2006 9:20 pm Post subject: Deleting a line from a text file. |
|
|
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 |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Mon Oct 02, 2006 11:54 pm Post subject: |
|
|
| 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 |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Mon Oct 02, 2006 11:58 pm Post subject: |
|
|
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 |
|
 |
Justdabomb2 Voice
Joined: 29 Sep 2006 Posts: 37 Location: United States of America
|
Posted: Tue Oct 03, 2006 3:44 pm Post subject: hmm |
|
|
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 |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Oct 03, 2006 5:43 pm Post subject: |
|
|
| read my last reply about glob. |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Oct 03, 2006 5:45 pm Post subject: |
|
|
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 |
|
 |
Justdabomb2 Voice
Joined: 29 Sep 2006 Posts: 37 Location: United States of America
|
Posted: Tue Oct 03, 2006 8:28 pm Post subject: ... wtf |
|
|
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 |
|
 |
Justdabomb2 Voice
Joined: 29 Sep 2006 Posts: 37 Location: United States of America
|
Posted: Tue Oct 03, 2006 8:43 pm Post subject: ... |
|
|
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 |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Oct 03, 2006 10:23 pm Post subject: |
|
|
| 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 |
|
 |
|