This is all pretty standard file manipulation. To get started, I suggest that you read the replies to "How to create a text file using Tcl/Tk?", thread287-222803, and follow the links provided there.
As for scanning for the particular ID, that depends a lot on the format of the data. You'll probably end up using one of the following Tcl commands, listed in increasing order or power and complexity:
string first,
string match,
scan, or
regexp.
And in Tcl, all time and date related information is handled by the
clock command.
To get more information about these commands and how to use them, I recommend searching the Tcl'ers Wiki, a collaboratively-edited collection of Tcl wisdom, at
Before I sign off, one idea I had is that if the file isn't too large, you might be able to take care of the scanning and updating with the following (untested):
Code:
# Assume the variable "file" contains the
# name of the log file.
# Opening the file in "a+" mode allows us to
# read from and write to the file. All
# writes are automatically appended to the
# end of the file.
set fid [open $file a+]
# Set the pointer to the beginning of the
# file, because opening the file in any "a"
# mode sets the pointer initially to the end
# of the file.
seek $fid 0
# Read the entire contents of the file
set text [read $fid [file size $file]]
# Assume the variable "id" contains your
# magic ID string.
if {[string first $id $text] == -1} {
# We didn't find the id in the file.
# Assume that the variable "record"
# contains the record we need to write.
# Write it to the end of the log file.
puts $fid $record
}
# Close the log file
close $fid
- Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax