| |||||||||||
Splitting a file into pieces Posted by enquirer (enquirer), 18 September 2002 The following question was asked by a person who has a really long file of data - an NC tool program."I want to parse a file ... spliting out sections that are marked between a start and an end marker I have inserted into separate files. How is it best to do this in Tcl" Posted by admin (Graham Ellis), 19 September 2002 So let's say our incoming file looks likeCode:
and we want two output files Code:
and Code:
Then we could use a program like Code:
in which we're basically openeing out two output files and then spraying the results to one or the other. Note that this simple "starter" code has some limitations - it will only handle one START or END per line, it gets into trouble if they're not nested correctly - but it's a starter to set you off in the write direction. Posted by admin (Graham Ellis), 1 October 2002 Just a footnote - I really should have closed my files after I finished with them; not usually necessaryto make the program work since buffers are flushed and a programn completed on exit, but with embedded applications you can't be 100% certain that the Tcl interpretter is going to be shut down properlyThis page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |