<?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/17275" />

	<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>2009-10-31T14:26:28-04:00</updated>

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

		<entry>
		<author><name><![CDATA[admiralboom]]></name></author>
		<updated>2009-10-31T09:52:34-04:00</updated>

		<published>2009-10-31T09:52:34-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=90709#p90709</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=90709#p90709"/>
		<title type="html"><![CDATA[I want to edit a line but clobbers the whole file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=90709#p90709"><![CDATA[
Thank you tomekk that did it.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10929">admiralboom</a> — Sat Oct 31, 2009 9:52 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Sir_Fz]]></name></author>
		<updated>2009-10-31T03:35:25-04:00</updated>

		<published>2009-10-31T03:35:25-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=90705#p90705</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=90705#p90705"/>
		<title type="html"><![CDATA[I want to edit a line but clobbers the whole file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=90705#p90705"><![CDATA[
This should be helpful: <a href="http://forum.egghelp.org/viewtopic.php?t=6885" class="postlink">Basic File Operations</a><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3085">Sir_Fz</a> — Sat Oct 31, 2009 3:35 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[tomekk]]></name></author>
		<updated>2009-10-31T14:26:28-04:00</updated>

		<published>2009-10-30T13:31:06-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=90695#p90695</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=90695#p90695"/>
		<title type="html"><![CDATA[I want to edit a line but clobbers the whole file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=90695#p90695"><![CDATA[
ahhh, my fault...<br><br>you can read whole file and later you can use some loop (for, foreach) to check the line<br><br>it will be smth like:<br>1. open file 'r', read whole content to some Var, close the file<br>2. open the same filem with 'w'<br>3. copy all from Var to this file (insert some IF inside loop, if line match - write it, if not - don't)<br>3. close the file<br><br>file.txt:<div class="codebox"><p>Code: </p><pre><code>onetwothree</code></pre></div>example.tcl:<div class="codebox"><p>Code: </p><pre><code>#!/usr/bin/tclshset read_data [open "file.txt" r]set all_lines [split [read $read_data] "\n"]close $read_dataset change "two"set write_data [open "file.txt" w]foreach file_line $all_lines {        if {$file_line != ""} {                if {$file_line == $change} {                        puts $write_data "woohooo"                } {                        puts $write_data $file_line                }        }}close $write_data</code></pre></div>file.txt after:<div class="codebox"><p>Code: </p><pre><code>onewoohoothree</code></pre></div>Its possible to this with one 'file open' by using 'seek' and 'a+' mode.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10332">tomekk</a> — Fri Oct 30, 2009 1:31 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[admiralboom]]></name></author>
		<updated>2009-10-30T13:14:00-04:00</updated>

		<published>2009-10-30T13:14:00-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=90693#p90693</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=90693#p90693"/>
		<title type="html"><![CDATA[I want to edit a line but clobbers the whole file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=90693#p90693"><![CDATA[
I suppose so although how do I tell it which line to edit?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10929">admiralboom</a> — Fri Oct 30, 2009 1:14 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[tomekk]]></name></author>
		<updated>2009-10-30T12:22:50-04:00</updated>

		<published>2009-10-30T12:22:50-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=90691#p90691</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=90691#p90691"/>
		<title type="html"><![CDATA[I want to edit a line but clobbers the whole file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=90691#p90691"><![CDATA[
if you want to append some data to end of file, use just <div class="codebox"><p>Code: </p><pre><code>set some_file_to_append [open $file a]</code></pre></div><a href="http://www.tcl.tk/man/tcl8.4/TclCmd/open.htm#M9" class="postlink">http://www.tcl.tk/man/tcl8.4/TclCmd/open.htm#M9</a><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10332">tomekk</a> — Fri Oct 30, 2009 12:22 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[admiralboom]]></name></author>
		<updated>2009-10-30T11:59:34-04:00</updated>

		<published>2009-10-30T11:59:34-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=90687#p90687</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=90687#p90687"/>
		<title type="html"><![CDATA[I want to edit a line but clobbers the whole file]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=90687#p90687"><![CDATA[
I need a suggestion on appending a line in the file without clobbering the whold file, suggestions?<br><div class="codebox"><p>Code: </p><pre><code>bind pub - !status proc_statusproc proc_status { ircnick userhost handle channel arg } {  set status "$arg"  if {$status == ""} {     puthelp "PRIVMSG $ircnick :Please supply your status"     return 0  }   set fs [open "/srv/httpd/htdocs/status.txt" r]   set tmpfs [open "/srv/httpd/htdocs/tmpstatus.txt" w]   set change 0   while {![eof $fs]} {        if {![gets $fs line]} {          puts -nonewline $tmpfs "$line\n"        } elseif {[lindex $line 1] == $ircnick} {          puts -nonewline $tmpfs "[unixtime] $ircnick $status\n"          set change 1        }    }   if {!$change} {        puts -nonewline $tmpfs "[unixtime] $ircnick $status"           puthelp "PRIVMSG $ircnick : Your status has been added."        }  else {           puthelp "PRIVMSG $ircnick : Your status has been updated."        }   close $fs   close $tmpfs   set tmpfs [open "/srv/httpd/htdocs/tmpstatus.txt" r]   set statusdb "[read $tmpfs]"   close $tmpfs   set fs [open "/srv/httpd/htdocs/status.txt" w]   puts -nonewline $fs "$statusdb"   close $fs   return 0}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10929">admiralboom</a> — Fri Oct 30, 2009 11:59 am</p><hr />
]]></content>
	</entry>
	</feed>
