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

	<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>2003-06-14T18:01:55-04:00</updated>

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

		<entry>
		<author><name><![CDATA[cerberus_gr]]></name></author>
		<updated>2003-06-14T18:01:55-04:00</updated>

		<published>2003-06-14T18:01:55-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=21827#p21827</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=21827#p21827"/>
		<title type="html"><![CDATA[&quot;Sort&quot; a file!]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=21827#p21827"><![CDATA[
Thx user. It works great, even if the syntax is weird  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_razz.gif" width="15" height="15" alt=":P" title="Razz"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2661">cerberus_gr</a> — Sat Jun 14, 2003 6:01 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[user]]></name></author>
		<updated>2003-06-14T14:35:40-04:00</updated>

		<published>2003-06-14T14:35:40-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=21821#p21821</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=21821#p21821"/>
		<title type="html"><![CDATA[&quot;Sort&quot; a file!]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=21821#p21821"><![CDATA[
Since the output will be the exact same size as the input you don't need to create a new file (using 'open' twice).<br><br>Open it using r+ and seek back to the start before writing the output:<div class="codebox"><p>Code: </p><pre><code>set file "sortme.txt"puts -nonewline [set f [open $file r+]] [join [lsort -dict -decr [split [read $f][seek $f 0] \n]] \n]close $f</code></pre></div>excuse my weird syntax <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2878">user</a> — Sat Jun 14, 2003 2:35 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[cerberus_gr]]></name></author>
		<updated>2003-06-14T12:03:35-04:00</updated>

		<published>2003-06-14T12:03:35-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=21816#p21816</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=21816#p21816"/>
		<title type="html"><![CDATA[&quot;Sort&quot; a file!]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=21816#p21816"><![CDATA[
Thank you both guys. The procedure that I have written was 46 lines <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_redface.gif" width="15" height="15" alt=":oops:" title="Embarassed"> and now it's 10 lines only and of course works better  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_biggrin.gif" width="15" height="15" alt=":D" title="Very Happy">  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_biggrin.gif" width="15" height="15" alt=":D" title="Very Happy"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2661">cerberus_gr</a> — Sat Jun 14, 2003 12:03 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Papillon]]></name></author>
		<updated>2003-06-13T17:39:01-04:00</updated>

		<published>2003-06-13T17:39:01-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=21789#p21789</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=21789#p21789"/>
		<title type="html"><![CDATA[&quot;Sort&quot; a file!]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=21789#p21789"><![CDATA[
yeah, go with stdragons solution, forgot about the blank lines  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_redface.gif" width="15" height="15" alt=":oops:" title="Embarassed"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=852">Papillon</a> — Fri Jun 13, 2003 5:39 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[stdragon]]></name></author>
		<updated>2003-06-13T17:22:28-04:00</updated>

		<published>2003-06-13T17:22:28-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=21788#p21788</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=21788#p21788"/>
		<title type="html"><![CDATA[&quot;Sort&quot; a file!]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=21788#p21788"><![CDATA[
You're right, -dict works too, I was just thinking of using the lsort -command option instead. You write a proc to compare 2 list items, returning -1, 0, or 1 (less than, equal, greater than). It's handy when you want to do complex sorting (like maybe you want to sort user handles by their flag levels, +n at the top etc).<br><br>You might want to change the way you read in the file though, because it will keep adding a new blank line at the end. This works a bit better:<div class="codebox"><p>Code: </p><pre><code>set fid [open $file r]set somelist [split [read -nonewline $fid] \n]close $fid</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8">stdragon</a> — Fri Jun 13, 2003 5:22 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Papillon]]></name></author>
		<updated>2003-06-13T16:20:13-04:00</updated>

		<published>2003-06-13T16:20:13-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=21784#p21784</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=21784#p21784"/>
		<title type="html"><![CDATA[&quot;Sort&quot; a file!]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=21784#p21784"><![CDATA[
<div class="codebox"><p>Code: </p><pre><code>set fid [open $file r]while {"[eof $fid]} {  gets $fid line  lappend somelist $line}catch {close $fid}set xid [open $file w]set somelist [lsort -dict -decreasing $somelist]foreach x $somelist {  puts $xid $x}catch {close $xid}</code></pre></div>something like this<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=852">Papillon</a> — Fri Jun 13, 2003 4:20 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[cerberus_gr]]></name></author>
		<updated>2003-06-13T14:39:34-04:00</updated>

		<published>2003-06-13T14:39:34-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=21780#p21780</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=21780#p21780"/>
		<title type="html"><![CDATA[&quot;Sort&quot; a file!]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=21780#p21780"><![CDATA[
Papillon a bit more help? <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_razz.gif" width="15" height="15" alt=":P" title="Razz"> does it works if the numbers are:<br>3, 12, 32 or I should have <strong class="text-strong">0</strong>3, 12, 32?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2661">cerberus_gr</a> — Fri Jun 13, 2003 2:39 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[cerberus_gr]]></name></author>
		<updated>2003-06-13T14:36:05-04:00</updated>

		<published>2003-06-13T14:36:05-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=21779#p21779</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=21779#p21779"/>
		<title type="html"><![CDATA[&quot;Sort&quot; a file!]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=21779#p21779"><![CDATA[
You mean that when I read a line to put in the right position in another file??<br>smt like this:<br><br>set a [open $file1 r]<br>set b [open $file1 w+]<br><br>while {![eof $a]} {<br>  gets $a linea<br>  set numa [lindex [split $linea] 0]<br><br>  while {![eof $fileb]} {<br>    gets $b lineb <br>    set numb [lindex [split $lineb] 0]   <br>    if {$numa &gt; $numb} { puts $numb $linea }   <br>    # Here I lose the content of previous line?  <br>  }<br>}<br><br><br>Could you help me a little more with the lsort command?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2661">cerberus_gr</a> — Fri Jun 13, 2003 2:36 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Papillon]]></name></author>
		<updated>2003-06-13T14:27:31-04:00</updated>

		<published>2003-06-13T14:27:31-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=21778#p21778</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=21778#p21778"/>
		<title type="html"><![CDATA[&quot;Sort&quot; a file!]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=21778#p21778"><![CDATA[
why would he need to compare the lines? all he wants to do is sort them by decreasing order<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=852">Papillon</a> — Fri Jun 13, 2003 2:27 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[stdragon]]></name></author>
		<updated>2003-06-13T14:16:29-04:00</updated>

		<published>2003-06-13T14:16:29-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=21777#p21777</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=21777#p21777"/>
		<title type="html"><![CDATA[&quot;Sort&quot; a file!]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=21777#p21777"><![CDATA[
Sure... open the file, read in everything, close it, split it by line, then write a proc to compare two lines (using lindex like you have), and sort the whole thing with lsort -command yourcommand. Then open the file again for writing, write the new list.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8">stdragon</a> — Fri Jun 13, 2003 2:16 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[cerberus_gr]]></name></author>
		<updated>2003-06-13T14:06:44-04:00</updated>

		<published>2003-06-13T14:06:44-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=21774#p21774</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=21774#p21774"/>
		<title type="html"><![CDATA[&quot;Sort&quot; a file!]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=21774#p21774"><![CDATA[
Hello,<br><br>I have a .txt file which looks like this:<br><em class="text-italics"><br>3 abcdsaaa<br>15 kljsfdfdfd<br>32 jdksdsds<br>6 khjaasa<br>15 dsdjsd<br></em><br>(it has some lines and the first [lindex [split $text] 0]] of all lines is a number)<br><br>Now I want to create a new .txt file where the first line would be this with the largest number, the second line would be this with the next number etc. For this example the file I want to be:<br><em class="text-italics"><br>32 jdksdsds<br>15 dsdjsd<br>15 kljsfdfdfd<br>6 khjaasa<br>3 abcdsaaa<br></em><br><br>(If two numbers are the same I don't have any problem which line would be upper than other.<br><br>Any ideas?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2661">cerberus_gr</a> — Fri Jun 13, 2003 2:06 pm</p><hr />
]]></content>
	</entry>
	</feed>
