egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Tcl Script for Sorting lines in File

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Zircon
Op


Joined: 21 Aug 2006
Posts: 191
Location: Montreal

PostPosted: Thu Jun 07, 2007 2:36 pm    Post subject: Tcl Script for Sorting lines in File Reply with quote

Hi all

i m lookin for a TCL script that can produce an output file by sorting the lines of an input file. The input file is a Trivia file.

Can some1 help me ? Thanks in advance
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Thu Jun 07, 2007 2:54 pm    Post subject: Reply with quote

Use the [lsort] Tcl-command to sort a list.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Zircon
Op


Joined: 21 Aug 2006
Posts: 191
Location: Montreal

PostPosted: Thu Jun 07, 2007 4:15 pm    Post subject: Reply with quote

Hi all

Thanks Sir_Fz for this hint. Unfortnately i don't know tcl, but i have a piece of code that can be a good start if some 1 can help to modify it to what i want. I think this code sorts the input file and make everything in a sigle line, like if we give it a c b in separate lines, it will return a b c in a single line in the output file. Me, i want to sort the file, but keep them in separate lines.


proc trivsort {} {
putlog "starting sorting......."
set f [open "input.txt" r]
set triv [read $f]
close $f
set trivlist [split $triv "\n"]
unset triv
lsort -increasing $trivlist
set f [open "output.txt" w]
puts $f $trivlist
close $f
putlog "sorting done.."
}

Thanks in advance
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Thu Jun 21, 2007 8:14 pm    Post subject: Reply with quote

Code:
proc trivsort {} {
 putlog "starting sorting......."
 set triv [lsort [split [read [set f [open input.txt]]] \n]][close $f]
 set f [open output.txt w]
 puts $f [join $triv \n]
 close $f
 putlog "sorting done.."
}

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Zircon
Op


Joined: 21 Aug 2006
Posts: 191
Location: Montreal

PostPosted: Fri Jun 22, 2007 4:10 am    Post subject: Reply with quote

Hello Sir_Fz

Thanks very much for your help, your script is fully working Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber