mIRC Home    About    Download    Register    News    Help

Print Thread
#131342 28/09/05 09:14 PM
Joined: Jan 2004
Posts: 133
W
Vogon poet
OP Offline
Vogon poet
W
Joined: Jan 2004
Posts: 133
i cant seem to find this doing a search ..

I want to search a txt file for a word / words
and have the results displayed messaged to the person.

like ..

!search help me

this would message the person all lines in the txt file that has "help me" in it..

Help ? lol thanks ...

#131343 28/09/05 09:31 PM
Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
something like $read(filename.txt,w, *wordofsearchhere*)

or use it in something simple like.. EX:. only i know this code is not for use to the vunerabilities of it... but this is what you can do similar well maybe n switch will prevent it.. since used has plain txt

on *:TEXT:*:#: {
if ($1 == !search) { msg $chan $read(filename.txt,nw, * $+ $2 $+ *) }
}

??

option w = scan txt file for word of course you can expand the search result to be direct.


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
#131344 28/09/05 09:33 PM
Joined: Jan 2004
Posts: 133
W
Vogon poet
OP Offline
Vogon poet
W
Joined: Jan 2004
Posts: 133
yea .. but need it to diplay ALL lines with that word or words ..

your exsample does first line it finds only i think

Last edited by WarlockW; 28/09/05 09:34 PM.
#131345 28/09/05 09:38 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
In its simplest form, something like:

Code:
on *:text:!search *:#channel:{
  filter -ffgc myfile.txt tmp /(?<= |^) $+ $2- $+ (?= |$)/i
  if ($filtered) play -m1q3 $nick tmp
}


Look up the flags I used by doing /help /play in mIRC. You can adapt them to fit your needs.


Gone.
#131346 28/09/05 09:46 PM
Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
LoLZ


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
#131347 28/09/05 09:57 PM
Joined: Jan 2004
Posts: 133
W
Vogon poet
OP Offline
Vogon poet
W
Joined: Jan 2004
Posts: 133
well that dont seem to work frown

um .. help ?

#131348 28/09/05 10:00 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Let me guess..you didn't change "myfile.txt" to the actual name of the file that holds the words.

Or you didn't change #channel to the appropriate channel.

Or you tried to test it yourself, and forgot that you cannot trip an on text event yourself, someone else must type it.


Gone.
#131349 28/09/05 10:03 PM
Joined: Jan 2004
Posts: 133
W
Vogon poet
OP Offline
Vogon poet
W
Joined: Jan 2004
Posts: 133
yes i changed them :P

and i am testing with different client ...

smile

still no work frown

#131350 28/09/05 10:06 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Did you copy the code correctly? There should be 4 lines...

If you did, then it simply means the string is not in the text file. Note that if you search for "the", that it won't trigger on the word "Athens", I've made it specifically so that it only reacts to the full word(s), not part of a word.


Gone.
#131351 28/09/05 10:11 PM
Joined: Jan 2004
Posts: 133
W
Vogon poet
OP Offline
Vogon poet
W
Joined: Jan 2004
Posts: 133
need it to find any word :P

and diplay all lines that have that word ...

darn it .. cant be that hard lol

#131352 28/09/05 10:13 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
It isn't, the thing I gave you is all you need, it works fine on my mIRC, which means you must be doing something wrong, or the word isn't in the file.

You still havent' said if "the" should or should not trigger on "Athens" btw. That makes an important difference.


Gone.
#131353 28/09/05 10:18 PM
Joined: Jan 2004
Posts: 133
W
Vogon poet
OP Offline
Vogon poet
W
Joined: Jan 2004
Posts: 133
no .. the shouldnt .. come up with athens

and i dont think i am doing it wrong ..

and yes the word is in the txt file several places.

thanks for the help btw smile

but just dont seem to work here .. i get no error though .. just
nothing displays as a result ..

this diplays a result ..
on *:TEXT:*:#: {
if ($1 == !search) { msg $chan $read(filename.txt,nw, * $+ $2 $+ *) }
}

However just the first one it finds not all lines ..

Last edited by WarlockW; 28/09/05 10:20 PM.
#131354 28/09/05 10:36 PM
Joined: Jan 2004
Posts: 133
W
Vogon poet
OP Offline
Vogon poet
W
Joined: Jan 2004
Posts: 133
ok ..

well it does work .. kinda ..

if i search .. the word THE

it finds LOTS of stuff lol
but the : the.erotrip

will not find : erotrip

weird

#131355 28/09/05 10:38 PM
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
didn't work here either, I recall my copy of mIRC didnt work with writing to tmp

I changed it to an alias to test


alias search {
write -c tmp.txt
filter -ffgc $sfile(*) tmp.txt /(?<= |^) $+ $2- $+ (?= |$)/i
if ($filtered) play -m1q3 tmp.txt
}

this did select lines out of the file, they had nothing to do with the search words I used however..

would really like to have a working copy of this

#131356 28/09/05 11:26 PM
Joined: Jan 2004
Posts: 133
W
Vogon poet
OP Offline
Vogon poet
W
Joined: Jan 2004
Posts: 133
also seems to be case sensitive lol

thats why it wasnt finding it smile

someone have any other ideas ?

#131357 28/09/05 11:42 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
  • It's not case sensitive at all, because the /i modifier is specified.

    Don't take my word for it, try it yourself on this example in your status window:

    //write -c test.txt | write test.txt $+(a,$lf,aa,$lf,aaa) | filter -ffcg test.txt tmp /(?<= |^)AA(?= |$)/i | filter -fs tmp *

    Note how I'm using "AA" as search text, yet it will echo to your window "aa", since the filter was case insensitive.
  • I specifically asked you if "the" should match in "athens" or not.

    From what I understood, you didn't want "the" to match in "athens", which means "the" shouldn't match in "the.erotrip". If you are contradictive in what you ask for, it is not surprisingly that the results will be awkward for you.

    If you want "the" to match in "the.erotrip" then it means if you specify an "a" it will match any word that has an "a" in it. If that's what you want, then change the filter to:

    filter -ffc myfile.txt tmp $+(*,$2-,*)
  • @Mikechat: I'm not surprised that your search results were strange, since you still have $2- in the alias, which should now be $1-.

    There's nothing wrong with writing to the file "tmp", I've done it hundreds of times in various scripts with no problems ever. What OS are you on? I'm positive it works on Win2k pro and WinXP, unless you perhaps have some kind of option on that somehow would prevent this.


I'm no longer participating in this thread.


Gone.
#131358 29/09/05 04:23 AM
Joined: Jul 2003
Posts: 655
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
Both exact and wildcard searches worked perfectly well for me, they must be doing something wrong. Please note that this code assumes myfile.txt is in the base mirc dir, if this is not the case you need to either specificy the full path (in quotes if it contains spaces), or specify the path relevent to the script file or mirc dir (/help $mircdir /help $scriptdir). The code i checked with is as follows, just how FiberOPtics posted it.

Also, if doing multiple word searches, do not use wildcards if you are using the regex method because these charactors have special meaning within a regular expression and may yeild undesirable results. When using the the second wildcard method, a space is treated as a space so you will have to use $replace (or a regsub) to replace spaces with *'s if you dont want to have to type them in the search. fex, with the current wildcard method, !search2 test abc will match *test abc* but will not match a line such as *test this abc*, but !search2 test*abc will match both.

Code:
on *:text:!search1 *:#:{
  filter -ffgc myfile.txt tmp /(?&lt;= |^) $+ $2- $+ (?= |$)/i
  if ($filtered) play -m1q3 $nick tmp
}

on *:text:!search2 *:#:{
  filter -ffc myfile.txt tmp $+(*,$2-,*)
  if ($filtered) play -m1q3 $nick tmp
}


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
#131359 29/09/05 04:35 AM
Joined: Jan 2004
Posts: 133
W
Vogon poet
OP Offline
Vogon poet
W
Joined: Jan 2004
Posts: 133
is there a way to stop it from displaying the same line twice ?

say in the txt file there is two lines that are the same ..

i only want 1 of the two lines to diplay ..

any ideas ?

#131360 29/09/05 05:55 AM
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Why have two of the same line? Why not filter out the duplicates.

#131361 29/09/05 05:58 AM
Joined: Jan 2004
Posts: 133
W
Vogon poet
OP Offline
Vogon poet
W
Joined: Jan 2004
Posts: 133
lol ..
ok how do i do that ?

plz ?


Link Copied to Clipboard