mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2004
Posts: 54
Cyclone Offline OP
Babel fish
OP Offline
Babel fish
Joined: Feb 2004
Posts: 54
I'm trying to search a text file for a matching text line and having serious problems. Yes it's embarressing because i thought this was a pretty much straight-forward task. I've read the mIRC helpfile and the commands I am using to try and acheive this from there give me errors.

//echo $read(info.txt, s, mirc)
Scans the file info.txt for a line beginning with the word mirc and returns the text following the match value.

//echo $read(help.txt, w, *help*)
Scans the file help.txt for a line matching the wildcard text *help*. The r switch implies a regex match.

Both these commands give me this output: * /echo: insufficient parameters

Is there any other way to search a file for matching text and output that text or line number please?

Help will be greatly appreciated... I am so dumb LconfusedL



Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
If the value returned in a number, echo will do that to you. echo treats a numeric value as a color value, and then continues to look for the actual text to output. Example:

/command
Output

/echo Hello
Hello

/echo 0
Insufficient parameters

/echo -a Hello
Hello (Active window)

/echo 0 Hello
Hello (black lettering)


-KingTomato
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
are you sure the paths to.txt files are correct


$maybe
Joined: Feb 2004
Posts: 54
Cyclone Offline OP
Babel fish
OP Offline
Babel fish
Joined: Feb 2004
Posts: 54
yeah... i checked all paths and filenames etc... I even used readme.txt in the $mircdir to make sure it wasn't working for me. No matter which file i try to scan or which line i try to locate... it gives me an error everytime frown

Is there any other way of scanning a text file to locate a line containing specified text that anyone knows of please?


Joined: Feb 2004
Posts: 54
Cyclone Offline OP
Babel fish
OP Offline
Babel fish
Joined: Feb 2004
Posts: 54
forgot to mention:

//echo $read(readme.txt,1) = works fine
//echo $read(readme.txt, s, mirc) = gives me an error: * /echo: insufficient parameters
//echo %read(readme.txt, w, *irc) = same error

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Use /echo -a instead of just /echo, otherwise mIRC might try to interpret the return value of $read() as various switches instead of as text to echo.

Also remember that with the s switch for plain text search $read() only returns the text coming after the text you searched for. So if a line was mirc and you searched with $read(somefile.txt, s, mirc) then it will return nothing even though it matched the line. To tell whether that's the case or not you must use $readn to see if it contains a non-zero value. I'll also point out that it will only match entire words using plain text search. For instance:

If a text file somefile.txt contained the line hello! world then the following things would occur:
$read(somefile.txt, s, hello!) -> returns world. $readn would return the line number it matched.
$read(somefile.txt, s, hello) -> returns nothing. $readn would return 0. This is because the first word in the line ends with a !, so mIRC will only match it if your search text contains one too.
$read(somefile.txt, s, hello! world) -> returns nothing. $readn would return the line number it matched. The line matched but there was nothing after the text that you searched for.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Feb 2004
Posts: 54
Cyclone Offline OP
Babel fish
OP Offline
Babel fish
Joined: Feb 2004
Posts: 54
Great info starbuck thanks very much. laugh

I've kind of got the hang of using $read switches now... but still have one problem. I'm trying to search in a file for matching text and return a value if $true, or nothing if $false.

i.e. If (mirc isin readme.txt) { echo -a $ifmatch }

Forgive the incorrect syntax. Is this possible... if so how please? smile

Joined: Apr 2004
Posts: 8
C
CNO Offline
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
C
Joined: Apr 2004
Posts: 8
hi,

assuming that any value not equal to 0 is $true ( like it is in C and afaik in mirc-script too ) you may try this:
it returns 0 ( -> $false ) if nothing was found, or the line number ( not 0 -> $true ) of the keyword's first occurance in the file.

-----
; $1 is the file to search in, $2 the keyword
alias isinFile {
var %temp = $read($1,w,* $+ $2 $+ *)
return $readn
}

if ($isinFile(the_file.txt, keyword)) { echo -a $ifmatch }
-----

Joined: Feb 2004
Posts: 54
Cyclone Offline OP
Babel fish
OP Offline
Babel fish
Joined: Feb 2004
Posts: 54
thanks m8... i'll give this bit of code a trial laugh

Joined: Feb 2004
Posts: 54
Cyclone Offline OP
Babel fish
OP Offline
Babel fish
Joined: Feb 2004
Posts: 54
errrm...

$isinfile( file,text )

Does this identifier exist???

confused

Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
alias isinFile {
var %temp = $read($1,w,* $+ $2 $+ *)
return $readn
}

The above is the identifier.


New username: hixxy
Joined: Feb 2004
Posts: 54
Cyclone Offline OP
Babel fish
OP Offline
Babel fish
Joined: Feb 2004
Posts: 54
DUH!!!!

I am so dumb... thanks tidy_trax laugh

If there weren't people like me around you'd be bored right? (Cyclone keeps assuring himself - LOL)


Link Copied to Clipboard