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

	<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>2010-05-05T05:39:41-04:00</updated>

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

		<entry>
		<author><name><![CDATA[arfer]]></name></author>
		<updated>2010-05-05T05:39:41-04:00</updated>

		<published>2010-05-05T05:39:41-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=93033#p93033</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=93033#p93033"/>
		<title type="html"><![CDATA[read,extract and count &gt;txt file in TCL]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=93033#p93033"><![CDATA[
It isn't clear whether this is a core Tcl project or something written for an Eggdrop bot, nevertheless I've provided an Eggdrop IRC public command !interface in the script below together with suitable output statements so that I can test it.<br><br>No directory/path is provided with the GLOB, FILE and OPEN commands, hence they default to the bots root directory.<br><br>The script searches all .txt files for the text 'interface xxxx' without regard to case, where xxxx is a four digit hexadecimal number.<br><br>Interface details are held in an array named iarray, where each array element name is the four digit hexadecimal number and the corresponding array element value is the frequency it occurs in the .txt files.<br><div class="codebox"><p>Code: </p><pre><code># interface.tclbind PUB n !interface pPubCommandproc pPubCommand {nick uhost hand channel txt} {    if {[llength [split [string trim $txt]]] == 0} {        pInterface        pOutput $channel    } else {putserv "PRIVMSG $channel :correct syntax is !interface without additional arguments"}    return 0}proc pInterface {} {    global flist iarray    unset -nocomplain iarray    set flist [lsort [glob -nocomplain -- *.txt]]    foreach item $flist {        set fp [open $item r]        set fdata [read $fp]        close $fp        while {[regexp -nocase -- {interface ([0-9a-f]{4})} $fdata -&gt; found]} {            set fdata [regsub -nocase -- $found $fdata ""]            set found [string tolower $found]            if {[info exists iarray($found)]} {incr iarray($found)} else {set iarray($found) 1}        }    }    return 0}proc pOutput {channel} {    global flist iarray    putserv "PRIVMSG $channel :\037files\037"    if {[llength $flist] != 0} {        foreach item $flist {            putserv "PRIVMSG $channel :$item [file size $item] bytes"        }        putserv "PRIVMSG $channel :\037interfaces\037"        if {[array size iarray] != 0} {            foreach item [lsort [array names iarray]] {                putserv "PRIVMSG $channel :interface $item frequency $iarray($item)"            }        } else {putserv "PRIVMSG $channel :no interfaces found"}    } else {putserv "PRIVMSG $channel :no files found"}    return 0}</code></pre></div>This is the original output (there are .txt files in the bot's root directory, but no text that matches the regular expression) :-<br><br>[09:54] &lt;@arfer&gt; !interface<br>[09:54] &lt;@osmosis&gt; <span style="text-decoration:underline">files</span><br>[09:54] &lt;@osmosis&gt; abuseat.txt 252 bytes<br>[09:54] &lt;@osmosis&gt; access.txt 12076 bytes<br>[09:54] &lt;@osmosis&gt; chanstats.txt 53 bytes<br>[09:54] &lt;@osmosis&gt; url.txt 0 bytes<br>[09:54] &lt;@osmosis&gt; <span style="text-decoration:underline">interfaces</span><br>[09:54] &lt;@osmosis&gt; no interfaces found<br><br>I created two .txt files in the bot's root directory as follows :-<br><br><span style="text-decoration:underline">test1.txt</span><br>this is a test<br>my Interface ac67 and my interface 458A<br>did i say InterFace AC67?<br><br><span style="text-decoration:underline">test2.txt</span><br>interface 432b<br>Interface 675c and InterfaCE AAAb<br>i think i said interface 458a in test1.txt<br>try 3 times ... interface bbb4, INTERFACE BBB4, inTERface bBb4<br><br>This is the script output after creating the two files :-<br><br>[10:13] &lt;@arfer&gt; !interface<br>[10:13] &lt;@osmosis&gt; <span style="text-decoration:underline">files</span><br>[10:13] &lt;@osmosis&gt; abuseat.txt 252 bytes<br>[10:13] &lt;@osmosis&gt; access.txt 12076 bytes<br>[10:13] &lt;@osmosis&gt; chanstats.txt 53 bytes<br>[10:13] &lt;@osmosis&gt; status.txt 371 bytes<br>[10:13] &lt;@osmosis&gt; test1.txt 84 bytes<br>[10:13] &lt;@osmosis&gt; test2.txt 159 bytes<br>[10:13] &lt;@osmosis&gt; url.txt 0 bytes<br>[10:13] &lt;@osmosis&gt; <span style="text-decoration:underline">interfaces</span><br>[10:13] &lt;@osmosis&gt; interface 432b frequency 1<br>[10:13] &lt;@osmosis&gt; interface 458a frequency 2<br>[10:13] &lt;@osmosis&gt; interface 675c frequency 1<br>[10:13] &lt;@osmosis&gt; interface aaab frequency 1<br>[10:13] &lt;@osmosis&gt; interface ac67 frequency 2<br>[10:13] &lt;@osmosis&gt; interface bbb4 frequency 3<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5705">arfer</a> — Wed May 05, 2010 5:39 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[passion]]></name></author>
		<updated>2010-04-26T20:10:02-04:00</updated>

		<published>2010-04-26T20:10:02-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=92929#p92929</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=92929#p92929"/>
		<title type="html"><![CDATA[read,extract and count &gt;txt file in TCL]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=92929#p92929"><![CDATA[
Hello folks,<br>I am quite new to TCL and seeking help from you guys to complete the following task. Thank you<br>I have to Search for the files with only .txt format in the current directory, count the number of cases of each different "Interface # nnnn" string in .txt file, where nnnn is a four or 32 digits max hexadecimal no and o/p of a table of Interface number against occurrence. I am facing implementation issues while writing a script i.e, Unable to implement the data structure like Linked List, Two Dimensional array. I am rewriting a script using multi dimension array (Pass values into the arrays in and out of procedure) in TCL to scan through the every .txt file and search for the the string/regular expression ‘Interface # ’ to count and display the number of occurrences. If someone could help me to complete this part will be much appreciated.<br>Here is my piece of code for searching a .txt file in present directory<br>Code:<br><div class="codebox"><p>Code: </p><pre><code>set files [glob *.txt]if { [llength $files] &gt; 0 } {    puts "Files:"    foreach f [lsort $files] {        puts "    [file size $f] - $f"    }} else {    puts "(no files)"}</code></pre></div>I reckon these are all the possible logical steps behind to complete it i) Once searched and find the .txt file then open all .txt files in read only mode ii) Create a array or list using the procedure (proc) Interface number to NULL and Interface count to zero 0 iii) Scan thro the .txt file and search for the string or regular expression "interface # iv) When a match found in .txt file, check the Interface Number and increment the count for the corresponding entry. Else add new element to the Interface Number list v) If there are no files return to the first directory<br><br>My o/p is like follows<br><div class="codebox"><p>Code: </p><pre><code>Code:Interface    Frequency123f            31232          4</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11189">passion</a> — Mon Apr 26, 2010 8:10 pm</p><hr />
]]></content>
	</entry>
	</feed>
