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.

.tcl search in .txt file with -nocase help

Support & discussion of released scripts, and announcements of new releases.
c
cbsjanten1
Voice
Posts: 4
Joined: Fri Jun 18, 2010 10:51 am

.tcl search in .txt file with -nocase help

Post by cbsjanten1 »

hey guys
i found this for some time ago and it works really fine for what im using it at
beside 1 thing
its case sentesive i would really like it to search in the .txt file with a -nocase mode
exampel !search Something would the return both something and Something
i have tryed with the -nocase insted of -all ... but i cant make it work
do any of u guys have a clue/hint on it? i would be very greatfull

Code: Select all

####################################################################################################
putlog "TextSearcher v0.2 - 1st Offcial Release by IsP (q_lander@hotmail.com)"
#
# This script simply searches a txt file (or text files) for search criteria specified via pub
# or msg commands. It Lets you search within a text file for key words using case insensitive
# trigger commands.
#
# Test on eggdrop v1.6.X.....use at own risk ;)
#
# This script was originally made from another script for 1Real by y0manda,
#    rewritten from ground up by IsP@Underent.org
#
# TODO: 
# - You tell me?
#
# v0.1 - 1st scripted
# v0.2 - Fixed the counter to display the correct count!
#      - Minor bug fix with proc $args - opps, was a mistake, honest ;P
#
####################################################################################################

#Where are the data files? (Use "{file location1} {file location2} {file location 3} {etc...}")
set cd_release ""

#Which channels do I check for the command?
set rlschans ""

#Max number of ourputs?
set rlsmaxsearch 9

#What's the public trigger?
set cmdsearch "!search"

#What Users are allowed to use this trigger/command? (Leave blank for anyone)
set rlsflag ""

#Set your inital tag info here
set rlsinfo ""

########## DO NOT EDIT BELOW ##########
if {$rlsflag == ""} {set rlsflag "-"}
bind pub $rlsflag $cmdsearch rlssearchpub
proc rlssearchpub {nick uhost handle chan arg} {
	global rlschans
	set valch 0
	foreach ch [split $rlschans] {if {$chan == $ch} {set valch 1}}
	if {$valch == 0} {return}
	rlslocate $chan $uhost $handle "PRIVMSG" "$arg"
}

bind msg $rlsflag $cmdsearch rlssearchmsg
proc rlssearchmsg {nick uhost handle arg} {
	global rlschans
	set valch 0
	foreach ch [split $rlschans] {if {[botonchan $ch]} {if {[onchan $nick $ch]} {set valch 1}}}
	if {$valch == 0} {return}
	rlslocate $nick $uhost $handle "PRIVMSG" "$arg"
}

proc rlslocate {nick uhost handle type arg} {
	global rlsmaxsearch cd_release rlsinfo
	if {$arg == ""} {puthelp "$type $nick :Syntax: $cmdsearch <search string>" ;return 0}
	regsub -all -- " " ${arg} "*" rlsarg
	puthelp "$type $nick : $rlsinfo ...Searching for '$rlsarg'"
	set totrlsfound 0
	foreach database $cd_release {
		set rlsfile [open $database r]
		while {![eof $rlsfile]} {
			set rlsline [gets $rlsfile]
			if {[string match "*$rlsarg*" $rlsline]} {
				incr totrlsfound 1
				if {$totrlsfound < $rlsmaxsearch} {
					puthelp "$type $nick : \002Found:\002 $rlsline"
				}
			}
		}
		close $rlsfile
	}
	if {$totrlsfound > $rlsmaxsearch} {puthelp "$type $nick :There are over $rlsmaxsearch matches. Please be more specific"}
	puthelp "$type $nick :There was a total of $totrlsfound entries matching your query."
}
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

Change

Code: Select all

if {[string match "*$rlsarg*" $rlsline]} {
to

Code: Select all

if {[string match -nocase "*$rlsarg*" $rlsline]} {
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
c
cbsjanten1
Voice
Posts: 4
Joined: Fri Jun 18, 2010 10:51 am

Post by cbsjanten1 »

thanx alot that solwes my ?

i was indeed looking in the wrong line - guess i have a lot to learn yet
thx again
I
IsP
Voice
Posts: 1
Joined: Mon Nov 22, 2010 9:30 am

Post by IsP »

hey thats my script!
E
Elements
Voice
Posts: 12
Joined: Thu Mar 19, 2009 11:33 am

Post by Elements »

i wonder if it can return more words per line or more lines
for each result than just one,
i am using it trying to pull up blocks of text from a book.
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

Can anyone please modify this script to search the file from BOTTOM to TOP instead of top to bottom? ie, return the top results starting from the last line to the first
d
dirty
Halfop
Posts: 40
Joined: Fri Feb 08, 2013 2:33 pm
Location: Romania
Contact:

Post by dirty »

For BOTTOM to UP results try this one.. I haven`t tested it but should work..

Replace this:

Code: Select all

proc rlslocate {nick uhost handle type arg} { 
   global rlsmaxsearch cd_release rlsinfo 
   if {$arg == ""} {puthelp "$type $nick :Syntax: $cmdsearch <search string>" ;return 0} 
   regsub -all -- " " ${arg} "*" rlsarg 
   puthelp "$type $nick : $rlsinfo ...Searching for '$rlsarg'" 
   set totrlsfound 0 
   foreach database $cd_release { 
      set rlsfile [open $database r] 
      while {![eof $rlsfile]} { 
         set rlsline [gets $rlsfile] 
         if {[string match "*$rlsarg*" $rlsline]} { 
            incr totrlsfound 1 
            if {$totrlsfound < $rlsmaxsearch} { 
               puthelp "$type $nick : \002Found:\002 $rlsline" 
            } 
         } 
      } 
      close $rlsfile 
   } 
   if {$totrlsfound > $rlsmaxsearch} {puthelp "$type $nick :There are over $rlsmaxsearch matches. Please be more specific"} 
   puthelp "$type $nick :There was a total of $totrlsfound entries matching your query." 
} 
With this:

Code: Select all

proc rlslocate {nick uhost handle type arg} { 
    global rlsmaxsearch cd_release rlsinfo 
    if {$arg == ""} {puthelp "$type $nick :Syntax: $cmdsearch <search string>" ;return 0} 
    regsub -all -- " " ${arg} "*" rlsarg 
    puthelp "$type $nick : $rlsinfo ...Searching for '$rlsarg'" 
    set totrlsfound 0 
	set alltext ""
    foreach database $cd_release { 
        set rlsfile [open $database r] 
        while {![eof $rlsfile]} { 
			set rlsline [gets $rlsfile] 
			if {[string match "*$rlsarg*" $rlsline]} { 
				incr totrlsfound 1 
				if {$totrlsfound < $rlsmaxsearch} { 
					lappend alltext $rlsline 
				} 
			} 
		} 
		close $rlsfile 
    }
	if {$alltext != ""} {
		foreach allline [lreverse $alltext] {
			puthelp "$type $nick : \002Found:\002 $allline"
		}
	}
   if {$totrlsfound > $rlsmaxsearch} {puthelp "$type $nick :There are over $rlsmaxsearch matches. Please be more specific"} 
   puthelp "$type $nick :There was a total of $totrlsfound entries matching your query." 
} 
come to the dark side.. I have cookies!
WwW.BotZone.TK
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

hey dirty, thanks for the reply - no, that did not work, it still searches from top to bottom
d
dirty
Halfop
Posts: 40
Joined: Fri Feb 08, 2013 2:33 pm
Location: Romania
Contact:

Post by dirty »

BigToe did you rehash/restart your eggdrop? Aldo I did not test that I`m pretty sure it should of worked.
come to the dark side.. I have cookies!
WwW.BotZone.TK
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

I restarted and it did not work
d
dirty
Halfop
Posts: 40
Joined: Fri Feb 08, 2013 2:33 pm
Location: Romania
Contact:

Post by dirty »

Can you please paste the script as you have it right now because I just tested it and it works fine.. I have it like this:

search_file.tcl

Code: Select all

#################################################################################################### 
putlog "TextSearcher v0.2 - 1st Offcial Release by IsP (q_lander@hotmail.com)" 
# 
# This script simply searches a txt file (or text files) for search criteria specified via pub 
# or msg commands. It Lets you search within a text file for key words using case insensitive 
# trigger commands. 
# 
# Test on eggdrop v1.6.X.....use at own risk ;) 
# 
# This script was originally made from another script for 1Real by y0manda, 
#    rewritten from ground up by IsP@Underent.org 
# 
# TODO: 
# - You tell me? 
# 
# v0.1 - 1st scripted 
# v0.2 - Fixed the counter to display the correct count! 
#      - Minor bug fix with proc $args - opps, was a mistake, honest ;P 
# 
#################################################################################################### 

#Where are the data files? (Use "{file location1} {file location2} {file location 3} {etc...}") 
set cd_release "scripts/MCC/search_file" 

#Which channels do I check for the command? 
set rlschans "#BotZone" 

#Max number of outputs? 
set rlsmaxsearch 9 

#What's the public trigger? 
set cmdsearch "!search" 

#What Users are allowed to use this trigger/command? (Leave blank for anyone) 
set rlsflag "" 

#Set your inital tag info here 
set rlsinfo "" 

########## DO NOT EDIT BELOW ########## 
if {$rlsflag == ""} {set rlsflag "-"} 
bind pub $rlsflag $cmdsearch rlssearchpub 
proc rlssearchpub {nick uhost handle chan arg} { 
   global rlschans 
   set valch 0 
   foreach ch [split $rlschans] {if {$chan == $ch} {set valch 1}} 
   if {$valch == 0} {return} 
   rlslocate $chan $uhost $handle "PRIVMSG" "$arg" 
} 

bind msg $rlsflag $cmdsearch rlssearchmsg 
proc rlssearchmsg {nick uhost handle arg} { 
   global rlschans 
   set valch 0 
   foreach ch [split $rlschans] {if {[botonchan $ch]} {if {[onchan $nick $ch]} {set valch 1}}} 
   if {$valch == 0} {return} 
   rlslocate $nick $uhost $handle "PRIVMSG" "$arg" 
} 

proc rlslocate {nick uhost handle type arg} { 
    global rlsmaxsearch cd_release rlsinfo 
    if {$arg == ""} {puthelp "$type $nick :Syntax: $cmdsearch <search string>" ;return 0} 
    regsub -all -- " " ${arg} "*" rlsarg 
    puthelp "$type $nick : $rlsinfo ...Searching for '$rlsarg'" 
    set totrlsfound 0 
   set alltext "" 
    foreach database $cd_release { 
        set rlsfile [open $database r] 
        while {![eof $rlsfile]} { 
         set rlsline [gets $rlsfile] 
         if {[string match "*$rlsarg*" $rlsline]} { 
            incr totrlsfound 1 
            if {$totrlsfound < $rlsmaxsearch} { 
               lappend alltext $rlsline 
            } 
         } 
      } 
      close $rlsfile 
    } 
   if {$alltext != ""} { 
      foreach allline [lreverse $alltext] { 
         puthelp "$type $nick : \002Found:\002 $allline" 
      } 
   } 
   if {$totrlsfound > $rlsmaxsearch} {puthelp "$type $nick :There are over $rlsmaxsearch matches. Please be more specific"} 
   puthelp "$type $nick :There was a total of $totrlsfound entries matching your query." 
} 
search_file

Code: Select all

a b c
d e f g
h i j b
k l b m
n t b
IRC test:

Code: Select all

[15:20] <+dirty> !search a
[15:20] <@BotZone>   ...Searching for 'a'
[15:20] <@BotZone>  Found: a b c
[15:20] <@BotZone> There was a total of 1 entries matching your query.
[15:20] <+dirty> !search b
[15:20] <@BotZone>   ...Searching for 'b'
[15:20] <@BotZone>  Found: n t b
[15:20] <@BotZone>  Found: k l b m
[15:20] <@BotZone>  Found: h i j b
[15:20] <@BotZone>  Found: a b c
[15:20] <@BotZone> There was a total of 4 entries matching your query.
come to the dark side.. I have cookies!
WwW.BotZone.TK
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

Ok I must have pasted it incorrectly - it works.
Thanks dirty!


I have another question though..


I have the following a line in the text file (it is the last line in the file)
Only Brazilian citizens can request a passport
When I typed !search Brazilian

It did not retrieve that line.

why?
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Believe that's because the script was still counting the found lines from the top of the file.
This version doesn't count found lines until after finding all matching lines and reversing their order.
Also, added a -nocase tag to the string match code, to make the search ignore case.

Code: Select all

#################################################################################################### 
putlog "TextSearcher v0.2 - 1st Offcial Release by IsP (q_lander@hotmail.com)" 
# 
# This script simply searches a txt file (or text files) for search criteria specified via pub 
# or msg commands. It Lets you search within a text file for key words using case insensitive 
# trigger commands. 
# 
# Test on eggdrop v1.6.X.....use at own risk ;) 
# 
# This script was originally made from another script for 1Real by y0manda, 
#    rewritten from ground up by IsP@Underent.org 
# 
# TODO: 
# - You tell me? 
# 
# v0.1 - 1st scripted 
# v0.2 - Fixed the counter to display the correct count! 
#      - Minor bug fix with proc $args - opps, was a mistake, honest ;P 
# 
#################################################################################################### 

#Where are the data files? (Use "{file location1} {file location2} {file location 3} {etc...}") 
set cd_release "scripts/MCC/search_file" 

#Which channels do I check for the command? 
set rlschans "#BotZone" 

#Max number of outputs? 
set rlsmaxsearch 9 

#What's the public trigger? 
set cmdsearch "!search" 

#What Users are allowed to use this trigger/command? (Leave blank for anyone) 
set rlsflag "" 

#Set your inital tag info here 
set rlsinfo "" 

########## DO NOT EDIT BELOW ########## 
if {$rlsflag == ""} {set rlsflag "-"} 
bind pub $rlsflag $cmdsearch rlssearchpub 
proc rlssearchpub {nick uhost handle chan arg} { 
   global rlschans 
   set valch 0 
   foreach ch [split $rlschans] {if {$chan == $ch} {set valch 1}} 
   if {$valch == 0} {return} 
   rlslocate $chan $uhost $handle "PRIVMSG" "$arg" 
} 

bind msg $rlsflag $cmdsearch rlssearchmsg 
proc rlssearchmsg {nick uhost handle arg} { 
   global rlschans 
   set valch 0 
   foreach ch [split $rlschans] {if {[botonchan $ch]} {if {[onchan $nick $ch]} {set valch 1}}} 
   if {$valch == 0} {return} 
   rlslocate $nick $uhost $handle "PRIVMSG" "$arg" 
} 

proc rlslocate {nick uhost handle type arg} { 
    global rlsmaxsearch cd_release rlsinfo 
    if {$arg == ""} {puthelp "$type $nick :Syntax: $cmdsearch <search string>" ;return 0} 
    regsub -all -- " " ${arg} "*" rlsarg 
    puthelp "$type $nick : $rlsinfo ...Searching for '$rlsarg'" 
    set totrlsfound 0 
    set alltext "" 
    foreach database $cd_release { 
        set rlsfile [open $database r] 
        while {![eof $rlsfile]} { 
         set rlsline [gets $rlsfile] 

         if {[string match -nocase "*$rlsarg*" $rlsline]} { 
            incr totrlsfound 1
 
            lappend alltext $rlsline 

         } 
        } 
        close $rlsfile 
    } 
    if {$alltext != ""} {

      set cnt 0
      foreach allline [lreverse $alltext] { 

         incr cnt
         if {$cnt > $rlsmaxsearch} {  break  }

         puthelp "$type $nick : \002Found:\002 $allline" 
      } 
    } 
    if {$totrlsfound > $rlsmaxsearch} {puthelp "$type $nick :There are over $rlsmaxsearch matches. Please be more specific"} 
    puthelp "$type $nick :There was a total of $totrlsfound entries matching your query." 
} 

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
d
dirty
Halfop
Posts: 40
Joined: Fri Feb 08, 2013 2:33 pm
Location: Romania
Contact:

Post by dirty »

Bleah .. good work Spike.. i forgot to modify that protection.
come to the dark side.. I have cookies!
WwW.BotZone.TK
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

Thanks dirty & Spike^^, much appreciated
Post Reply