| View previous topic :: View next topic |
| Author |
Message |
Zircon Op
Joined: 21 Aug 2006 Posts: 191 Location: Montreal
|
Posted: Thu Jun 07, 2007 2:36 pm Post subject: Tcl Script for Sorting lines in File |
|
|
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 |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
|
| Back to top |
|
 |
Zircon Op
Joined: 21 Aug 2006 Posts: 191 Location: Montreal
|
Posted: Thu Jun 07, 2007 4:15 pm Post subject: |
|
|
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 |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Thu Jun 21, 2007 8:14 pm Post subject: |
|
|
| 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 |
|
 |
Zircon Op
Joined: 21 Aug 2006 Posts: 191 Location: Montreal
|
Posted: Fri Jun 22, 2007 4:10 am Post subject: |
|
|
Hello Sir_Fz
Thanks very much for your help, your script is fully working  |
|
| Back to top |
|
 |
|