|
|
Joined: Feb 2007
Posts: 91
Babel fish
|
OP
Babel fish
Joined: Feb 2007
Posts: 91 |
Hello. Could someone post a snippet, that would search a txt file for lines which contain part of the typed text? For example the file is: mp_101_kfs8 mp_ske_asf mp_213_p0r mp_101_kro 101_ksd_34m mp_ksd_w0q ksd_213_ras mp_wk2_ksd
So when user types !search 101, it will show msg him in diferent lines like this: 1. Found mp_101_kfs8 in the file. 2. Found mp_101_kro in the file. 3. Found 101_ksd_34m in the file.
But if there are more than 3 results like, if user types !search ksd, it will show
1. Found 101_ksd_34m in the file. 2. Found mp_ksd_w0q in the file 3. Found ksd_213_ras in the file. 4. There are more than 3 results for "ksd" . Try being more correct.
Hope that you understood what i ment. Thanks.
Last edited by spermis; 04/03/09 03:10 PM.
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
/filter your file to a temp file to strip non-matching lines
Count the $lines remaining in the file
$read up to the first 3 lines
If there are more than 3 lines display your warning message
/remove the temp file
-genius_at_work
|
|
|
|
Joined: Jul 2006
Posts: 4,144
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,144 |
on *:text:!search *:#:{
filter yourtextfile.txt out.txt * $+ $2-*
var %a = 1, %b = $iif($filtered > 3,3,$v1)
while (%a <= %b) {
.timer 1 1 msg $chan Found $read(out.txt,%a) in the file.
if (%a == 3) && ($filtered >= 3) {
.timer 1 1 msg $chan There are more than 3 results for " $+ $2", try being more correct.
break
}
inc %a
}
.remove out.txt
} Replace yourtextfile.txt with your file and try it, I have not tested, but should work. Edit : the code is doing what genius_at_work said, but instead of strip non matching line, it put all matching line in a file.
Last edited by Wims; 04/03/09 03:34 PM.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Feb 2007
Posts: 91
Babel fish
|
OP
Babel fish
Joined: Feb 2007
Posts: 91 |
on *:text:!search *:#:{
filter yourtextfile.txt out.txt * $+ $2-*
var %a = 1, %b = $iif($filtered > 3,3,$v1)
while (%a <= %b) {
.timer 1 1 msg $chan Found $read(out.txt,%a) in the file.
if (%a == 3) && ($filtered >= 3) {
.timer 1 1 msg $chan There are more than 3 results for " $+ $2", try being more correct.
break
}
inc %a
}
.remove out.txt
} Replace yourtextfile.txt with your file and try it, I have not tested, but should work. Edit : the code is doing what genius_at_work said, but instead of strip non matching line, it put all matching line in a file. Somehow nothing is happening at all
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
Try this modification of Wims' code. Instead of timers it will /filter to a 2nd tempfile to get the desired format and /play this file to the channel. Make sure you put a valid source file. on *:text:!search *:#:{
; #### Put line limit and sourcefile here. ####
; If the sourcefile isn't located in mIRCs main directory, you have to put the complete path and filename
var %limit = 3, %file = test.txt
; filter lines that match the searchterm to 1st tempfile
filter -ffc $qt(%file) !search.temp1 * $+ $2-*
if ($filtered) {
var %matches = $v1
; chop matches to %limit lines by filtering to 2nd tempfile and get the desired output format in this file
filter -fknr $+(1-,%limit) !search.temp1 searchformat
; if the line limit was hit: add trailing line to 2nd tempfile
if (%matches > %limit) { write !search.temp2 There are %matches results for $qt($2-) $+ , output limit is: %limit $+ . Try being more correct. }
; output content of 2nd tempfile to the channel with 750ms delay per line
.play -q3m1 $chan !search.temp2 750
.remove !search.temp2
}
else { .msg $chan Found no matches for $qt($2-) $+ . }
.remove !search.temp1
}
alias -l searchformat {
tokenize 32 $1-
write $+(-l,$1) !search.temp2 $1 $+ . Found $2- in the file.
}
Edit: removed a redundant check for $2-
|
|
|
|
Joined: Feb 2007
Posts: 91
Babel fish
|
OP
Babel fish
Joined: Feb 2007
Posts: 91 |
Thanks. Working nice and smooth
|
|
|
|
Joined: Jul 2006
Posts: 4,144
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,144 |
Just in case, here the corrected code of mine : on *:text:!search *:#:{
filter yourfilehere.txt out.txt * $+ $2-*
var %a = 1, %b = $iif($filtered > 3,3,$v1)
while (%a <= %b) {
.timer 1 %a msg $chan Found $!( $qt($read(out.txt,n,%a)) ,0) in the file.
if (%a == 3) && ($filtered >= 3) {
.timer 1 4 msg $chan There are more than 3 results for " $+ $2", try being more correct.
}
if (%a == 3) .remove out.txt
inc %a
}
if (!$filtered) echo -a msg $chan No match found
}
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
|
|