mIRC Homepage

help with $read a line from a file

Posted By: Cyclone

help with $read a line from a file - 05/07/04 11:15 AM

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


Posted By: KingTomato

Re: help with $read a line from a file - 05/07/04 11:54 AM

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)
Posted By: Mpdreamz

Re: help with $read a line from a file - 05/07/04 01:02 PM

are you sure the paths to.txt files are correct
Posted By: Cyclone

Re: help with $read a line from a file - 05/07/04 01:17 PM

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?

Posted By: Cyclone

Re: help with $read a line from a file - 05/07/04 01:20 PM

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
Posted By: starbucks_mafia

Re: help with $read a line from a file - 05/07/04 02:47 PM

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.
Posted By: Cyclone

Re: help with $read a line from a file - 05/07/04 04:21 PM

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
Posted By: CNO

Re: help with $read a line from a file - 05/07/04 08:21 PM

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 }
-----
Posted By: Cyclone

Re: help with $read a line from a file - 12/07/04 06:17 AM

thanks m8... i'll give this bit of code a trial laugh
Posted By: Cyclone

Re: help with $read a line from a file - 12/07/04 03:22 PM

errrm...

$isinfile( file,text )

Does this identifier exist???

confused
Posted By: tidy_trax

Re: help with $read a line from a file - 12/07/04 03:24 PM

alias isinFile {
var %temp = $read($1,w,* $+ $2 $+ *)
return $readn
}

The above is the identifier.
Posted By: Cyclone

Re: help with $read a line from a file - 12/07/04 03:35 PM

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)
© 2021 mIRC Discussion Forums