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.

writing to a text file

Old posts that have not been replied to for several years.
Locked
f
fizzik

Post by fizzik »

i am NEW to tcl scripting, i am trying to create a script that users can search and delete items from a separate file containing the items, i have the searching part worked out, i am having trouble with the deleting of items. each item is on a separate line. is there anyway of deleting a line in tcl? Because currently i am overwriting the line and in a lot of cases this causes the next line to be messed up because i don't know how to overwrite the exact amount of characters in the line i want to kill. Could some one please see if they understand what im saying, and if you coul kick me in the right direction i would REALLY appreciate it.

cheers

<font size=-1>[ This Message was edited by: fizzik on 2002-06-15 01:29 ]</font>
W
Wcc
Master
Posts: 278
Joined: Sun Oct 28, 2001 8:00 pm
Location: USA
Contact:

Post by Wcc »

You can't delete a line directly with Tcl. You need to read the entire file, remove the line, and rewrite the file.

Wcc
P
Petersen
Owner
Posts: 685
Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK

Post by Petersen »

yup, which personally I try to avoid when I can - the unix standard utils (grep, sed, cut and the like) tend to be quicker for large files
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

We should make a little fileutil.tcl that has all these commonly used functions in them. People seem to ask several main questions:

how do I read a random line

how do I delete a line

how do I search for a line

how do I read all the lines into a list

how do I insert a line at the (beginning|end)

But I guess these are the same people who are too lazy to search for the answers that have already been given. They probably wouldn't bother getting the file. :(
f
fizzik

Post by fizzik »

thanks for the replies. stdragon, i have searched EXTENSIVELY looking for a answer but i obviously dont know what to search for, could you please give me a pointer on what to search for? thanks.
Locked