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.

newbiez: how to delete a line from text file?

Old posts that have not been replied to for several years.
Locked
J
JudgeFred

newbiez: how to delete a line from text file?

Post by JudgeFred »

Hi,

I'm trying to write a script for eggdrop that received user input and search for that input (a line) in the text file then delete.

For example:
/msg botnick !delete remove-this-line-in-the-text-file

then the result should remove the line "remove-this-line-in-the-text-file" in the textfile.txt.


Also need to play back the textfile.txt back to user when user issued command: /msg botnick !list

thanks all,

GT
d
dollar
Op
Posts: 178
Joined: Tue Oct 28, 2003 3:47 pm
Location: Netherlands

Post by dollar »

Read the text file, and copy all lines to an temporary file except the one you want to remove. Then just replace the old with the new.
dollar (or something similar) at:
#eggdrop / #tcl - undernet
#egghelp / #tcl / #eggtcl - efnet
#eggdrop.support / #tcl - quakenet
#eggdrop - ircnet
User avatar
KrzychuG
Master
Posts: 306
Joined: Sat Aug 16, 2003 2:51 pm
Location: Torun, Poland
Contact:

Post by KrzychuG »

I found this code here at forum few month ago:

Code: Select all

# Usage: replaceLines <file> <first line> <last line> [replacement data (optional)]
proc replaceLines { args } {
   if {[llength $args] >= 3} then {
      foreach {file start end} $args break
      set cmd [list lreplace [split [read [set f [open $file r]]] \n] $start $end]
      close $f
      if {[llength $args] > 3} then {lappend cmd [lindex $args 3]}
      puts -nonewline [set f [open $file w]] [join [eval $cmd] \n]
      close $f
   } else {
      error "wrong # args: should be \"[lindex [info level 0] 0] file start end ?replacement?\""
   }
} ;# replaceLines
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Try this thread.
It has Basic file operation commands.

****
http://forum.egghelp.org/viewtopic.php?t=6885
****
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Locked