mIRC Home    About    Download    Register    News    Help

Print Thread
$read(filename.txt, s, test1) not working #198769 04/05/08 09:27 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
I have a text file named filename.txt and in it is:

test1
test2
test3

When I type //echo $read(filename.txt, s, test1) nothing echos back to the screen. What am i doing wrong?

When I type //echo -a $lines(filename.txt) it echo's back the correct number of lines in the file.


I registered; you should too.
Re: $read(filename.txt, s, test1) not working [Re: AWEstun] #198772 04/05/08 09:47 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
You aren't specifying where the echo should go
Quote:
/echo [color] [-cdeghiNtsaqlbfnmr] [color name] [#channel|[=]nick] <text>

Prints text in the specified window using the specified color (0 to 15).

/echo 3 #mIRC Testing

would print "Testing" in the color green in channel window #mIRC, assuming it's already open.

If a channel/nickname isn't specified, the -s switch echoes to the status window, the -d switch echoes to the single message window, and the -a switch echoes to the currently active window.


Try
Code:
//echo -a $read(filename.txt,s,test1)

Re: $read(filename.txt, s, test1) not working [Re: RusselB] #198774 04/05/08 09:52 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Thanks. I can't get the s switch to work, but the w switch with a * on the end of the search text did. For example:

//echo -a read(filename.txt,w,test1*)

This echos back: Test1

So why doesn't the s switch work?


I registered; you should too.
Re: $read(filename.txt, s, test1) not working [Re: AWEstun] #198775 04/05/08 10:10 AM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Read the help file:
Quote:
//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.

It's not returning anything because the is nothing *after* test1. If you make the line read "test1 hello" then your $read will return "hello".

Re: $read(filename.txt, s, test1) not working [Re: 5618] #198776 04/05/08 10:22 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Ah, that makes sense! I was reading the mirc help file, but i wasn't sure if it'd return what it found and the test after or just the text after what it found. Thanks for clearing that up.


I registered; you should too.
Re: $read(filename.txt, s, test1) not working [Re: AWEstun] #198779 04/05/08 11:00 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
How do I add a * to the end of a string? I.E. $4 $+ *

I tried

if $read(filename.txt,w,$4 $+ * == $null ) { write filename.txt $4 }

but i dont think that is working.

Basically I'm trying to search filename.txt for a string and if that string is not found, add it.


I registered; you should too.
Re: $read(filename.txt, s, test1) not working [Re: AWEstun] #198780 04/05/08 11:10 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
You just have a misplaced closing bracket. Change

if $read(filename.txt,w,$4 $+ * == $null ) { write filename.txt $4 }

to

if $read(filename.txt,w,$4 $+ *) == $null { write filename.txt $4 }


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: $read(filename.txt, s, test1) not working [Re: qwerty] #198781 04/05/08 11:14 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Heh, yeah I just noticed that too.

Is there any kind of program that will resort a text file by the first letter of the line?


I registered; you should too.
Re: $read(filename.txt, s, test1) not working [Re: AWEstun] #198782 04/05/08 11:26 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
/filter -ffca file.txt file.txt

will sort the file alphabetically, although not just by first letter (ie it will sort by first letter, but the words that have the same first letter will be sorted by second letter etc).

For more sorting options, you'd need to use the -t switch (/help /filter).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: $read(filename.txt, s, test1) not working [Re: qwerty] #198789 04/05/08 01:35 PM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Thanks.

When I use $read to seach, it return the first match, but how can I get it to show all matches?


I registered; you should too.
Re: $read(filename.txt, s, test1) not working [Re: AWEstun] #198793 04/05/08 01:49 PM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
Again, with /filter, look in the help file for this command :
Code:
//filter in.txt out.txt *text*
Here out.txt will contain all line of in.txt that match *text*.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: $read(filename.txt, s, test1) not working [Re: Wims] #198796 04/05/08 03:24 PM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Originally Posted By: Wims
Again, with /filter, look in the help file for this command :
Code:
//filter in.txt out.txt *text*
Here out.txt will contain all line of in.txt that match *text*.


Thanks, but that's not what I was looking for. I removed the duplicates by using an external program.


I registered; you should too.
Re: $read(filename.txt, s, test1) not working [Re: AWEstun] #198797 04/05/08 03:40 PM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
How do I search if there are more than one match in the file? Let's say I'm searching for 'apple' and the text file has this:

orange
applepie
appleshake
banana
applesmoothie

if I do a $read(filename.txt,w,apple*) that will only show me 'applepie'. So how do I get it to show me the other matches too, like 'appleshake' and 'applesmoothie'?


I registered; you should too.
Re: $read(filename.txt, s, test1) not working [Re: AWEstun] #198800 04/05/08 05:10 PM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Like Wims said, you can use /filter and then $read the output .txt

Alternatively, you could do a dirty method like...
Code:
alias {
  var %line = 1
  while ($read(filename.txt,w,apple*,%line)) {
    echo -a $read(filename.txt,w,apple*,%line)
    var %line = $calc($readn +1)
  }
}

That sets the line to start the next wildcard match from to the one after the previous matched line ($readn).

Re: $read(filename.txt, s, test1) not working [Re: 5618] #198801 04/05/08 05:13 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
You should use $v1 within the loop instead of re-searching the file otherwise you're doing double the necessary work.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: $read(filename.txt, s, test1) not working [Re: starbucks_mafia] #198803 04/05/08 06:00 PM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Originally Posted By: starbucks_mafia
You should use $v1 within the loop instead of re-searching the file otherwise you're doing double the necessary work.

Yes, you are completely right. It's so obvious yet easy to forget.
So my initial echo should be changed to "echo -a $v1".

Re: $read(filename.txt, s, test1) not working *DELETED* [Re: 5618] #198824 05/05/08 01:29 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Thanks, this was exactly what I'm looking for.


I registered; you should too.
Re: $read(filename.txt, s, test1) not working [Re: AWEstun] #198829 05/05/08 02:06 AM
Joined: Dec 2002
Posts: 2,021
R
RoCk Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,021

Yes. The result of the $read in the while loop is already stored in $v1 so echoing the result using the $read identifier again is totally unnecessary and as starbucks_mafia said, it would be searching the file again when the result is already available in $v1.

/help $v1