This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.
For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.
Help for those learning Tcl or writing their own scripts.
-
romain
- Voice
- Posts: 12
- Joined: Sun Oct 16, 2005 1:51 am
Post
by romain »
Hello,
In the file with more lines
......
[00:17] <test> [05joueur1] :: [game1] [point]
[00:17] <test> [03Joueur2] :: [game2] [point]
[00:18] <test> |[06totaljoueur] :: [totalgame] [totalpoint]
.....
How to write only the line with "totaljoueur" for have this result
|[06totaljoueur] :: [totalgame] [totalpoint]
thx for help
-
game_over
- Voice
- Posts: 29
- Joined: Thu Apr 26, 2007 7:22 am
Post
by game_over »
you have to know where is the word
example:
word word word word
word word word word
word1 word word word
i search where in my file i have
word1
Code: Select all
set hcs [open $file r]; set scorefile [split [read $hcs] "\n"]; close $hcs
foreach newscore $scorefile {
if {[lindex $newscore 0] == "word1"} {
set scoreall $newscore; # scoreall is my total line :)
}
}
unset scorefile
putlog "total: [lindex $scoreall 1] [lindex $scoreall 2]"
if i whant to sum all resalts and write total under all scores
Code: Select all
set scoreall1 0; scoreall2 0
set hcs [open $file r]; set scorefile [split [read $hcs] "\n"]; close $hcs
foreach newscore $scorefile {
if {[lindex $newscore 0] != "totaljoueur" || [lindex $newscore 0] != ""} {
set scoreall1 [expr [lindex $newscore 1] + $scoreall1]
set scoreall2 [expr [lindex $newscore 2] + $scoreall2]
}
}
set writedata [open $file w]
foreach newdata $scorefile {
if {[lindex $newdata 0] != "totaljoueur"} {
puts $writedata "$newdata"
} elseif {[lindex $newdata 0] != ""} {
puts $writedata "totaljoueur $scoreall1 $scoreall2"
}
}
flush $writedata; close $writedata; unset scorefile
when script resum all set new total line under and remove old