<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/8959" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2005-01-17T17:02:08-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/8959</id>

		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2005-01-17T17:02:08-04:00</updated>

		<published>2005-01-17T17:02:08-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=45490#p45490</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=45490#p45490"/>
		<title type="html"><![CDATA[Db controll open file add search remove TEXT not decimal]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=45490#p45490"><![CDATA[
<blockquote class="uncited"><div>i have try it don't work<br>get same error as my own script<br> <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_confused.gif" width="15" height="15" alt=":?" title="Confused">  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_sad.gif" width="15" height="15" alt=":(" title="Sad"></div></blockquote>The error is from 'lreplace' - go read the manual.<br><br>Here's a couple of procs to give you some ideas (not tested, so there might be bugs)<br><br>1: using 'string match -nocase' on every line.<br>This one writes every non-matching line to a temp file then overwrites the original at the end if there were any matches<div class="codebox"><p>Code: </p><pre><code>proc fdel {file what} {set i 0while {[file exists $file.[incr i]]} {}set file2 $file.$iset f1 [open $file]set f2 [open $file2 w]set n 0while {[gets $f1 line]&gt;-1} {if {[string match -nocase $what $line]} {incr n} {puts $f2 $line}}close $f1close $f2if $n {file rename -force $file2 $file} {file delete $file2}set n}</code></pre></div>2: using 'lsearch' on the entire contents of the file (case sensitive)<br>This one reads the entire file, does the deleting and then creates the file all over if any lines were deleted. It lets you decide the mode used for 'lsearch' and also has an option for replacing all matching lines or just the first one.<div class="codebox"><p>Code: </p><pre><code>proc fdel2 {file what {mode -glob} {all 0}} {set f [open $file]set data [split [read $f] \n]close $fset n 0[expr {$all?"while":"if"] {[set i [lsearch $mode $data $what]]&gt;-1} {set data [lreplace $data $i $i]incr n}if $n {set f [open $file w]puts -nonewline $f [join $data \n]close $f}set n}</code></pre></div>...they both return the number of lines deleted<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Mon Jan 17, 2005 5:02 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[willienl]]></name></author>
		<updated>2005-01-17T10:11:59-04:00</updated>

		<published>2005-01-17T10:11:59-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=45482#p45482</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=45482#p45482"/>
		<title type="html"><![CDATA[Db controll open file add search remove TEXT not decimal]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=45482#p45482"><![CDATA[
i have try it don't work<br>get same error as my own script<br> <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_confused.gif" width="15" height="15" alt=":?" title="Confused">  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_sad.gif" width="15" height="15" alt=":(" title="Sad"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5871">willienl</a> — Mon Jan 17, 2005 10:11 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[willienl]]></name></author>
		<updated>2005-01-10T16:12:56-04:00</updated>

		<published>2005-01-10T16:12:56-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=45247#p45247</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=45247#p45247"/>
		<title type="html"><![CDATA[Db controll open file add search remove TEXT not decimal]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=45247#p45247"><![CDATA[
when type !del test23<br>i get<br><br>Tcl error [pub:del]: bad index "test23": must be integer or end?-integer?<br><br>when type !del 2<br>i get none<br>with my own way of try <br>i'll ty your example and i tell if i can use it or not<br>it is for me i don't matter line nr`s <br>i must be able to delete the word somthing on line 200 of 600 lines <br>600 lines each line an user ident or host<br><br>like <br>nick1<br>nick2 <br>nick3<br>nick4<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5871">willienl</a> — Mon Jan 10, 2005 4:12 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2005-01-10T13:07:37-04:00</updated>

		<published>2005-01-10T13:07:37-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=45242#p45242</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=45242#p45242"/>
		<title type="html"><![CDATA[Re: Db controll open file add search remove TEXT not decimal]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=45242#p45242"><![CDATA[
<blockquote class="uncited"><div>i get an error when i type !test 3 then not but nothing happend</div></blockquote>What error did you get? Read it - and don't use the argument name 'args' before you've read the <a href="http://www.tcl.tk/man/tcl8.5/TclCmd/proc.htm" class="postlink">proc</a> manual. (it has a special meaning)<br><br>Here's a proc that might be of use to you:<div class="codebox"><p>Code: </p><pre><code># imagine that the lines in your file are elements in a list# and use this proc like 'lreplace' (check the manual)## to delete the last line: freplace your.txt end# to replace the first line: freplace your.txt 0 0 "New first line"proc freplace {file args} {# check argumentsswitch [llength $args] {1 {lappend args [lindex $args 0]}2 - 3 {}default {error "usage: freplace &lt;fileName&gt; &lt;firstLine&gt; \[lastLine \[replacementData\]\]"}}# read fileset f [open $file]set lines [split [read $f] \n]close $f# replace line(s)set lines [eval [list lreplace $lines] $args]# write fileset f [open $file w]puts -nonewline $f [join $lines \n]close $f}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Mon Jan 10, 2005 1:07 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[willienl]]></name></author>
		<updated>2005-01-10T04:14:37-04:00</updated>

		<published>2005-01-10T04:14:37-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=45220#p45220</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=45220#p45220"/>
		<title type="html"><![CDATA[Db controll open file add search remove TEXT not decimal]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=45220#p45220"><![CDATA[
Hi there i saw mod`s remove post`s <br>with requests about file open in tcl<br>many times i se no way to fix it and here on this<br>forum the talk about many times discussing it where<br>are those post so i can learn from that   <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_confused.gif" width="15" height="15" alt=":?" title="Confused"> <br><br>here my script<br>can someone help me fixing the del option<br>thnx will<br><br>################ Set Db var`s ################<br>if {![file exists test.txt]} {<br>  set fs [open test.txt a]<br>  puts $fs "db script"<br>  close $fs<br>}<br><br>################ Find args  ################<br>bind pub - "!find" pub:search<br>proc pub:search {nick host hand channel args} { <br>set file "test.txt"<br>set found 0 <br>set fs [open $file r] <br>while {![eof $fs]} { <br>  gets $fs line <br>  if {$line == $args} { set found 1 } <br>} <br>close $fs <br>if {$found} { <br>  putquick "PRIVMSG $channel :$nick $args was found!" <br>} else { <br>  putquick "PRIVMSG $channel :$nick $args was not found." <br>} <br>  return 0<br>}<br><br>################ Add args ################<br>bind pub - "!add" pub:addin<br>proc pub:addin {nick host hand channel args} { <br>set file "test.txt"<br>set found 0 <br>set fs [open $file r] <br>while {![eof $fs]} { <br>  gets $fs line <br>  if {$line == $args} { set found 1 } <br>} <br>close $fs <br>if {$found == "1"} { <br>  putquick "PRIVMSG $channel :$args was found!" <br>} else { set fs [open $file a]<br> puts $fs "$args" <br> close $fs<br> putquick "PRIVMSG $channel :$args was add!"  <br>} <br>  return 0<br>}<br><br>################ Del args  ################<br>bind pub - "!del" pub:del<br>proc pub:del {nick host hand channel args} { <br>set file "test.txt"<br>set found 0 <br>set fs [open $file r] <br>while {![eof $fs]} { <br>  gets $fs line <br>  if {$line == $args} {<br>  set found 1<br>  set result $line } <br>} <br>close $fs <br>if {$found == "1"} { <br>  putquick "PRIVMSG $channel :$args was found!" <br>} else { putquick "PRIVMSG $channel :$args was add!"  <br>} <br>  return 0<br>}<br><br>#the line to check if it is in my db file<br>#is done<br>#when i try to remove word3<br>#i get an error when i type !test 3 then not but nothing happend<br>#<br><br>bind pub - "!test pub:test<br>proc pub:test {nick host hand channel args} {<br>set file "test.txt"<br>set fp [open $file "r"]<br>set data [read -nonewline $fp]<br>close $fp<br><br>set lines [split $data "\n"]<br>set lines [lreplace $lines $args $args]<br><br>set fp [open $fp "w"]<br>puts $fp [join $lines "\n"]<br>close $fp <br>  return 0<br>}<br><br><br><br>my file test.txt looks like this<br><br>word1<br>word2<br>word3<br>word4<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5871">willienl</a> — Mon Jan 10, 2005 4:14 am</p><hr />
]]></content>
	</entry>
	</feed>
