| View previous topic :: View next topic |
| Author |
Message |
Meropie Voice
Joined: 19 Dec 2007 Posts: 7
|
Posted: Tue Feb 05, 2008 10:44 am Post subject: hi, a snippet is needed. |
|
|
hello, im searching for a snippet to delete a line from a file.
my file looks like:
bla
bla2
bla4
meropie
egghelp
and such..
i want to delete a line, but i am searching the whole line, so it will be much easier (i think).
example:
i want to delete meropie, i will search for meropie and delete it so the file will look like:
bla
bla2
bla4
egghelp
.
thanks. |
|
| Back to top |
|
 |
Maiki Voice
Joined: 20 May 2007 Posts: 28
|
Posted: Tue Feb 05, 2008 10:51 am Post subject: |
|
|
| Code: | bind pub - !delete delLine
proc delLine {nick uhost hand chan arg} {
set file [open /usr/dir r]
set data [read -nonewline $file]
close $file
if {[set pos [lsearch -glob [set ldata [split $data \n]] $arg]] != -1} {
set data [open /usr/dir w]
puts $data [join [lreplace $ldata $pos $pos] \n]
close $data
putserv "PRIVMSG $chan :Deleted $arg"
} else {
close $data
putserv "PRIVMSG $chan :Can not find $arg in the file"
}
}
|
|
|
| Back to top |
|
 |
Meropie Voice
Joined: 19 Dec 2007 Posts: 7
|
Posted: Tue Feb 05, 2008 10:57 am Post subject: |
|
|
yo, thanks for the help, but error accurs:
[16:57] Tcl error [delLine]: can not find channel named "Meropie" |
|
| Back to top |
|
 |
Maiki Voice
Joined: 20 May 2007 Posts: 28
|
Posted: Tue Feb 05, 2008 11:03 am Post subject: |
|
|
Fixed..  |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
|
| Back to top |
|
 |
|