| View previous topic :: View next topic |
| Author |
Message |
StaleJoke Voice
Joined: 29 Nov 2005 Posts: 10
|
Posted: Wed Jun 07, 2006 11:54 am Post subject: Insert Line After Regular Interval |
|
|
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: |
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 ? |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Wed Jun 07, 2006 12:09 pm Post subject: |
|
|
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] tag when posting logs, code |
|
| Back to top |
|
 |
|