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 

regexp?

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
romain
Voice


Joined: 16 Oct 2005
Posts: 12

PostPosted: Mon Nov 03, 2008 7:15 pm    Post subject: regexp? Reply with quote

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
View user's profile Send private message
game_over
Voice


Joined: 26 Apr 2007
Posts: 29

PostPosted: Tue Nov 04, 2008 5:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help 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