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.

txt file

Old posts that have not been replied to for several years.
J
Jag
Halfop
Posts: 90
Joined: Fri Sep 19, 2003 10:06 am

txt file

Post by Jag »

How can i remove a specific line from a txt file in a command?
User avatar
CrazyCat
Revered One
Posts: 1286
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

read each line:
if line matches => do nothing
if line doesn't match => put in tmp file

when eof, delete original file and rename tmp file as original.
J
Jag
Halfop
Posts: 90
Joined: Fri Sep 19, 2003 10:06 am

Post by Jag »

CrazyCat wrote: when eof, delete original file and rename tmp file as original.
how do i use the "eof" command?
can you give me an example please?
10x :P
User avatar
GodOfSuicide
Master
Posts: 463
Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria

Post by GodOfSuicide »

Code: Select all

set badtext "mybadtext"

set in [open myfile.txt "r"]
set out [open myfile.txt.tmp "w+"]
while {![eof $in]} {
 set line [gets $in]
 if {$line != $badtext} {
  puts $out $line
 }
}
close $in
close $out
exec "rm myfile.txt"
exec "cp myfile.txt.tmp myfile.txt"
exec "rm myfile.txt.tmp"
would remove every line that doesnt EXACT match with $badtext from a file.
you should do the file delete & rename stuff with the TCL Commands which have been written for this, i'm just too tired of looking them up.
J
Jag
Halfop
Posts: 90
Joined: Fri Sep 19, 2003 10:06 am

Post by Jag »

GodOfSuicide wrote:

Code: Select all

exec "rm myfile.txt"
exec "cp myfile.txt.tmp myfile.txt"
exec "rm myfile.txt.tmp"
this commands are for eggdrop and not windrop, am i right?
User avatar
CrazyCat
Revered One
Posts: 1286
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

yes, I confirm :)
don't really know if it's possible with windrop...
J
Jag
Halfop
Posts: 90
Joined: Fri Sep 19, 2003 10:06 am

Post by Jag »

:(
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

change:

Code: Select all

exec "rm myfile.txt" 
exec "cp myfile.txt.tmp myfile.txt" 
exec "rm myfile.txt.tmp" 
to:

Code: Select all

file delete myfile.txt
file rename myfile.txt.tmp myfile.txt
User avatar
GodOfSuicide
Master
Posts: 463
Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria

Post by GodOfSuicide »

Jag wrote: this commands are for eggdrop and not windrop, am i right?
they are for unix

i told you to look up the tcl file commands
http://www.tcl.tk/man/tcl8.4/TclCmd/file.htm

€ - ah, strikelight was faster again :P
J
Jag
Halfop
Posts: 90
Joined: Fri Sep 19, 2003 10:06 am

Post by Jag »

10x ! :P
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

this commands are for eggdrop and not windrop, am i right?
Yes you can if you use "-n" option on start but this will move the bot into forground, if you install your eggdrop as a service then you won't have the forground proces ;) well it won't show any way but don't make it interact with your desktop
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

and why use exec ???

Code: Select all

#Usage: [badtext:filter mytextfile.txt badtext]

proc  badtext:filter {filename badtext} {
  set rfile [open "$filename" "r"] 
  set wfile [open "tmp/$filename.tmp" "w"] 
  while {![eof $rfile]} { 
    gets $rfile line
    if {![string match -nocase "*$badtext*" $line]} { 
      puts $wfile $line 
    } 
  } 
  close $rfile 
  close $wfile
  set rfile [open "tmp/$filename.tmp" "r"]
  set wfile [open "$filename" "w"]
  foreach line [split [read $rfile] \n] {
    puts $wfile $line
  }
  close $rfile
  close $wfile
}
and from what i can say this is os independent ;)
XplaiN but think of me as stupid
User avatar
GodOfSuicide
Master
Posts: 463
Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria

Post by GodOfSuicide »

Ofloo wrote:and why use exec ???
and why use 5 files for your ip-to-country script?
somethimes ppl are just too lazy (i know i am)
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

well its written in the top thats its crapy code and needs rewrite :p can't say lazy more like if i don't know stuff i work arround it ! on my way so .. more like inventive :p but hell not saying your scripting is bad just trying to help out :p sorry if you took it personal
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

GodOfSuicide wrote:And why use 5 files for your ip-to-country script?
and if you do got suggestions plz post :p, and for futur suggestions use email in the top of the script.
XplaiN but think of me as stupid
Locked