Hello!
I made a script but now I can't get on because I don't know how to delete all lines except for the first. That means I need a code that deletes all lines from the second till the end. Can anybody help me?
after so many requests for help, you should have known by now that any manipulation of text files is best done in memory - that is, you read the entire file into a list, manipulate the list, and write it back to disk file
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use
# Use the code from above (1.) to read in all the lines from the file.
# We continue right after: set lines [split $data "\n"]
# We'll delete the first line.
set line_to_delete 0
# If you wanted to delete the last line instead, you would do this:
# set line_to_delete [expr [llength $lines] - 1]
# Now, we remove the line from the list in memory first.
set lines [lreplace $lines $line_to_delete $line_to_delete]
# And finally, we re-write the file with the new data.
set fp [open $fp "w"]
puts $fp [join $lines "\n"]
close $fp
But here only one line is deleted. What do I have to change that all lines from the second till the end are deleted.