mIRC Home    About    Download    Register    News    Help

Print Thread
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.
Joined: Aug 2004
Posts: 7,252
R
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)

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.
Joined: Jun 2007
Posts: 933
5
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".

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.
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.
Joined: Jan 2003
Posts: 2,523
Q
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
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.
Joined: Jan 2003
Posts: 2,523
Q
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
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.
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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*.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
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.
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.
Joined: Jun 2007
Posts: 933
5
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).

Joined: Dec 2002
Posts: 2,962
S
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.
Joined: Jun 2007
Posts: 933
5
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".

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.
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

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


Link Copied to Clipboard