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.

File Opperations help

Help for those learning Tcl or writing their own scripts.
Post Reply
S
SL0RD
Voice
Posts: 19
Joined: Sun Oct 05, 2008 11:44 am

File Opperations help

Post by SL0RD »

First off, say you had this:

Code: Select all


thing1 disc
thing2 disc
thing3 disc
thing4 disc

I would like to add a new line but if the line that i want to add starts with thing1 for example instead of adding it again at the end i want to update the existing thing1
also how could you delete a line by using lsearch but by searching the first word in each line so i would like to delete things3 for example by searching for thing3

secondly, say you had that same table, I want to be able to do a command and have it pull the first word from every line and list it in the channel ex: <bot> thing1, thing2, thing3, thing4

thanks to anyone who helps me with this.
g
game_over
Voice
Posts: 29
Joined: Thu Apr 26, 2007 7:22 am

Post by game_over »

when i whant to delete line in file i use foreach

see when you find line who starts for example thing1 you replase whit new and dont write again.

firest you read txt split to lines "\n"

and foreach line you set some if

when if is false "== 0" you write old line when is true "==1" you write new line

in this sense if you whant to delete some line just miss them

if {[lindex $lineforomtheforech 0] == "thing1"} {;# do nothing} else {puts "$lineforomtheforech"; #same line is writen again}


first row seems to look this way

Code: Select all

set listforfirstrow ""
set opentxt [open $sometxt "r"]; set format [split [read $opentxt] "\n"]; close $opentxt 

forech firstrow $format {
 set listforfirstrow "$listforfirstrow [lindex $firstrow 0]"
}

putquick "PRIVMSG $chan : $listforfirstrow"
Post Reply