| View previous topic :: View next topic |
| Author |
Message |
cbsjanten1 Voice
Joined: 18 Jun 2010 Posts: 4
|
Posted: Fri Jun 18, 2010 11:02 am Post subject: .tcl search in .txt file with -nocase help |
|
|
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: | ####################################################################################################
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."
}
|
|
|
| Back to top |
|
 |
username Op

Joined: 06 Oct 2005 Posts: 196 Location: Russian Federation, Podolsk
|
Posted: Fri Jun 18, 2010 2:50 pm Post subject: |
|
|
Change | Code: | | if {[string match "*$rlsarg*" $rlsline]} { | to | Code: | | if {[string match -nocase "*$rlsarg*" $rlsline]} { |
_________________ Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/ |
|
| Back to top |
|
 |
cbsjanten1 Voice
Joined: 18 Jun 2010 Posts: 4
|
Posted: Fri Jun 18, 2010 3:32 pm Post subject: |
|
|
thanx alot that solwes my ?
i was indeed looking in the wrong line - guess i have a lot to learn yet
thx again |
|
| Back to top |
|
 |
IsP Voice
Joined: 22 Nov 2010 Posts: 1
|
Posted: Mon Nov 22, 2010 9:31 am Post subject: |
|
|
| hey thats my script! |
|
| Back to top |
|
 |
Elements Voice
Joined: 19 Mar 2009 Posts: 12
|
Posted: Mon Jan 03, 2011 1:50 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Thu Feb 21, 2013 5:06 am Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
dirty Halfop
Joined: 08 Feb 2013 Posts: 40 Location: Romania
|
Posted: Thu Feb 21, 2013 7:51 am Post subject: |
|
|
For BOTTOM to UP results try this one.. I haven`t tested it but should work..
Replace this:
| Code: |
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: |
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 |
|
| Back to top |
|
 |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Thu Feb 21, 2013 8:36 am Post subject: |
|
|
| hey dirty, thanks for the reply - no, that did not work, it still searches from top to bottom |
|
| Back to top |
|
 |
dirty Halfop
Joined: 08 Feb 2013 Posts: 40 Location: Romania
|
Posted: Thu Feb 21, 2013 8:48 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Thu Feb 21, 2013 9:03 am Post subject: |
|
|
| I restarted and it did not work |
|
| Back to top |
|
 |
dirty Halfop
Joined: 08 Feb 2013 Posts: 40 Location: Romania
|
Posted: Thu Feb 21, 2013 9:22 am Post subject: |
|
|
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: |
####################################################################################################
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: |
a b c
d e f g
h i j b
k l b m
n t b
|
IRC test:
| Code: |
[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 |
|
| Back to top |
|
 |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Thu Feb 21, 2013 9:55 am Post subject: |
|
|
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)
| Quote: |
Only Brazilian citizens can request a passport
|
When I typed !search Brazilian
It did not retrieve that line.
why? |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Thu Feb 21, 2013 12:28 pm Post subject: |
|
|
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: |
####################################################################################################
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
. |
|
| Back to top |
|
 |
dirty Halfop
Joined: 08 Feb 2013 Posts: 40 Location: Romania
|
Posted: Thu Feb 21, 2013 1:43 pm Post subject: |
|
|
Bleah .. good work Spike.. i forgot to modify that protection. _________________ come to the dark side.. I have cookies!
WwW.BotZone.TK |
|
| Back to top |
|
 |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Thu Feb 21, 2013 1:48 pm Post subject: |
|
|
| Thanks dirty & Spike^^, much appreciated |
|
| Back to top |
|
 |
|