| View previous topic :: View next topic |
| Author |
Message |
romain Voice
Joined: 16 Oct 2005 Posts: 12
|
Posted: Mon Nov 03, 2008 7:15 pm Post subject: regexp? |
|
|
Hello,
In the file with more lines
| Quote: |
......
[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
| Quote: | | |[06totaljoueur] :: [totalgame] [totalpoint] |
thx for help |
|
| Back to top |
|
 |
game_over Voice
Joined: 26 Apr 2007 Posts: 29
|
Posted: Tue Nov 04, 2008 5:08 pm Post subject: |
|
|
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: |
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: |
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 |
|
| Back to top |
|
 |
|