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.

how to delete a whole line in a textfile ?

Old posts that have not been replied to for several years.
Locked
M
Maverick

how to delete a whole line in a textfile ?

Post by Maverick »

i made a script to store newslines in a textfile. Everything works fine, add news, list news, and so on. But deleting a line doesn´t work. I have no idea how to solve that thing :(
W
Wcc
Master
Posts: 278
Joined: Sun Oct 28, 2001 8:00 pm
Location: USA
Contact:

Post by Wcc »

Read the file, delete the line, write the file again.

Wcc
M
Maverick

Post by Maverick »

that´s my question Wcc !
I dont know how. I need an example because there is no command to delete a line in a textfile. Please give me an example.
W
Wcc
Master
Posts: 278
Joined: Sun Oct 28, 2001 8:00 pm
Location: USA
Contact:

Post by Wcc »

Try this:

Code: Select all

proc deleteline {file line} {
  set fd [open $file r]
  set data [split [read $fd] "\n"]
  close $fd
  set data [lreplace $data [expr $line - 1] [expr $line - 1]]
  set fd [open $file w]
  puts $fd [join $data "\n"]
  close $fd
}
Wcc
M
Maverick

Post by Maverick »

thats great :D thanks for your help !
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

You might want to add -nonewline to your puts statement.

puts -nonewline ...
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

-nonewline

Post by stdragon »

You might want to add -nonewline to your puts statement.

puts -nonewline ...
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

-nonewline

Post by stdragon »

You might want to add -nonewline to your puts statement.

puts -nonewline ...
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

err, it was giving me an error, I swear! lol

something like "general error - could not find notify_email template"

so I hit reload.. I guess it was posting the whole time!
User avatar
slennox
Owner
Posts: 593
Joined: Sat Sep 22, 2001 8:00 pm
Contact:

Post by slennox »

Well, now I can't delete them because your last message would be out of context :P
User avatar
slennox
Owner
Posts: 593
Joined: Sat Sep 22, 2001 8:00 pm
Contact:

Post by slennox »

Hmm, I just received the same error when posting that. After looking up the error in the phpbb2 forums, I suspect anyone else who replies to this thread will run into the error, although the post will get through. Seems a lot of phpbb2 users are having this problem, but I couldn't see a fix.
Last edited by slennox on Sun Jul 07, 2002 10:34 pm, edited 1 time in total.
User avatar
slennox
Owner
Posts: 593
Joined: Sat Sep 22, 2001 8:00 pm
Contact:

Post by slennox »

Hmm, now the "last edited" message is showing up all of a sudden? :lol:
Locked