From WikiChip
Editing mirc/identifiers/$read
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.
Latest revision | Your text | ||
Line 2: | Line 2: | ||
== Synopsis == | == Synopsis == | ||
− | < | + | <pre>$read(filename [, ntswrp] [,matchtext] [, N] ) |
− | |||
Legacy syntax: | Legacy syntax: | ||
− | + | $read [switches] [line#] filename</pre> | |
== Parameters == | == Parameters == | ||
Line 18: | Line 17: | ||
| t | Do not treat a numeric line#1 as if it's the total number of lines in the text file. | | t | Do not treat a numeric line#1 as if it's the total number of lines in the text file. | ||
| s | Search for line beginning with <matchtext> and returns the remainder of the line beyond the spaces following <matchtext> | | s | Search for line beginning with <matchtext> and returns the remainder of the line beyond the spaces following <matchtext> | ||
− | | w | Scan for line matching <matchtext> which can be a | + | | w | Scan for line matching <matchtext> which can be a wildcard. If not a wildcard the line must be exact match. Returns the entire contents of the matching line |
| r | Indicates that <matchtext> is a regex pattern. | | r | Indicates that <matchtext> is a regex pattern. | ||
| p | When evaluating text in the absence of the 'n' switch, treats the pipe symbol as a command separator allowing the remainder of the line to be executed as a /command. | | p | When evaluating text in the absence of the 'n' switch, treats the pipe symbol as a command separator allowing the remainder of the line to be executed as a /command. | ||
}} | }} | ||
− | |||
=== Notes: === | === Notes: === | ||
* All searches are case-insensitive. | * All searches are case-insensitive. | ||
Line 30: | Line 28: | ||
* matchtext must have the presence/absence of spaces in order to match lines having/not-having those spaces, even leading/trailing/consecutive. | * matchtext must have the presence/absence of spaces in order to match lines having/not-having those spaces, even leading/trailing/consecutive. | ||
* Undocumented legacy syntax can be used where parameters follow the identifier without being enclosed within quotes. | * Undocumented legacy syntax can be used where parameters follow the identifier without being enclosed within quotes. | ||
− | |||
== Examples == | == Examples == | ||
<source lang="mIRC"> | <source lang="mIRC"> | ||
− | //echo -a | + | //echo -a line $readn is $read(versions.txt,nt) |
returns: a random line from versions.txt even if it is $null | returns: a random line from versions.txt even if it is $null | ||
Note: You can use $read(quotes.txt,nt) as your quit message, and it will display a random line from that file when you /quit a server. | Note: You can use $read(quotes.txt,nt) as your quit message, and it will display a random line from that file when you /quit a server. | ||
− | |||
− | |||
− | |||
− | |||
//echo -a $read(versions.txt,nt,3) | //echo -a $read(versions.txt,nt,3) | ||
− | returns: | + | returns: line #3 |
//echo -a $read(versions.txt,nt,2) | //echo -a $read(versions.txt,nt,2) | ||
− | returns: | + | returns: line #2. if the line length is blank (length = 0), returns $null |
//echo -a $read(versions.txt,nt,invalid) | //echo -a $read(versions.txt,nt,invalid) | ||
returns: If s/r/w switches not used and 3rd parameter is used without being a number >= 1, returns line #1. | returns: If s/r/w switches not used and 3rd parameter is used without being a number >= 1, returns line #1. | ||
− | //echo -a $read(file.txt,t, | + | //echo -a $read(file.txt,t,4) |
− | returns: Contents of line#3. Because the 'n' switch wasn't used, evaluates any | + | returns: Contents of line#3. Because the 'n' switch wasn't used, evaluates any identifiers instead of returning strings beginning with "S". |
− | //echo -a $read(file.txt,tp, | + | //echo -a $read(file.txt,tp,4) |
returns: Same, except if the line contains the | "pipe" symbol, that is treated as a command separator, and the portion beyond the pipe is executed as if a script command. | returns: Same, except if the line contains the | "pipe" symbol, that is treated as a command separator, and the portion beyond the pipe is executed as if a script command. | ||
Line 60: | Line 53: | ||
//echo -a $read(versions.txt,nts,10.fixed,200) line: $readn | //echo -a $read(versions.txt,nts,10.fixed,200) line: $readn | ||
matches: Same, except begins scanning at line 200. | matches: Same, except begins scanning at line 200. | ||
− | |||
− | |||
− | |||
//echo -a $read(versions.txt,nts,changes:) $readn | //echo -a $read(versions.txt,nts,changes:) $readn | ||
Line 79: | Line 69: | ||
returns first line containing exactly 3 space-tokenized 'words'. | returns first line containing exactly 3 space-tokenized 'words'. | ||
− | + | //var %i 1 | :label | echo -ag $read(versions.txt,ntw,* - mirc*,%i) $readn | var %i = 1 + $readn | if ($readn) goto label | |
− | //var %i 1 | | + | returns all lines of the file matching the matchtext |
//write -c test.dat top line | var %i 2 | while (%i isnum 2-100) { write test.dat line %i | inc %i } | //write -c test.dat top line | var %i 2 | while (%i isnum 2-100) { write test.dat line %i | inc %i } | ||
− | This creates a 100-line file, where the 1st line says "top line" and lines 2-99 | + | This creates a 100-line file, where the 1st line says "top line" and lines 2-99 show their line number. |
− | //write -l1 test.dat top | echo -a $read(test.dat,n) | + | //write -l1 test.dat top | echo -a $read(test.dat,n) |
Because Line#1 is not a number, mIRC does not treat it as a line count for the file, so this returns a random line from the text file. | Because Line#1 is not a number, mIRC does not treat it as a line count for the file, so this returns a random line from the text file. | ||
− | //write -l1 test.dat 40 | echo -a $read(test.dat,n) | + | //write -l1 test.dat 40 | echo -a $read(test.dat,n) $readn |
− | Now that line#1 is | + | Now that line#1 is a number, returns a random line from line 2 through N+1, so it's possible for this to return $readn 1-40 when reading from lines 2-41. |
+ | //write -c test.dat 40 | write test.dat test2 | echo -a with n: $read(test.dat,n,0) . $readn without n: $read(test.dat,0) $readn | ||
//var %pattern \d{5,} | echo -a $read(versions.txt,ntr,%pattern) $readn | //var %pattern \d{5,} | echo -a $read(versions.txt,ntr,%pattern) $readn | ||
− | 'r' switch indicates matchtext is a regex pattern. Returns: first line containing at least 5 consecutive number digits | + | 'r' switch indicates matchtext is a regex pattern. Returns: first line containing at least 5 consecutive number digits |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</source> | </source> | ||
− | |||
== Compatibility == | == Compatibility == | ||
For modern documented syntax: | For modern documented syntax: |