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.

Insert Line After Regular Interval

Help for those learning Tcl or writing their own scripts.
Post Reply
S
StaleJoke
Voice
Posts: 10
Joined: Tue Nov 29, 2005 8:04 pm

Insert Line After Regular Interval

Post by StaleJoke »

If this is covered somewhere else then please direct me there because i couldnt find it.

I am trying to insert a line in a text file, starting after a certain line and then at regular intervals till eof.

Not to mention that this works in a wierd way.

Code: Select all

proc main {nick host hand chan rest} {
	global opfile
	set logfile [open $opfile(list) r]
	set lines [split [read -nonewline $logfile] "/n"]
	set totlines [llength $lines]
	set fp [open $opfile(final) a]
	set num 7
	while {$num <= $totlines} {
		set lines [linsert $lines $num $opfile(insert)]
		puts $fp [join $lines "\n"]
		set num [expr {$num + 5}]
	} 
	close $fp 
	close $logfile
}
Any help ?
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

1. read the file into list in memory
2. manipulate the list using [linsert] or [lreplace]
3. write the list back to disk file
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
Post Reply