Project

General

Profile

$read » History » Version 2

Per Amundsen, 02/23/2023 07:22 PM

1 1 Per Amundsen
_Added in 1.9.0_
2
3
*$read(filename, [ntswrp], [matchtext], [N])*
4
5
Returns a single line of text from a file.
6
7
_See also [[$readn]]._
8
9
*Parameters*
10
11 2 Per Amundsen
table(ktable).
12
|*Parameter*|*Description*|
13
| filename | Filename to read. |
14
| [ntswrp] | (optional) |
15
| [matchtext] | Matchtext to search. (optional) |
16
| [N] | The Nth line. |
17 1 Per Amundsen
18 2 Per Amundsen
*Options*
19
20
table(ktable).
21
|*Option*|*Description*|
22
| n | Don't evaluate any identifiers in the line. |
23
| t | Treat the first line as a plain text, even if it's a number. |
24
| s | Search for matchtext. |
25
| w | Search for matchtext as a wildmatch. |
26
| r | Search for matchtext as a regular expression. |
27
| p | Treat command <notextile>|</notextile> separators as such instead of as plain text. |
28 1 Per Amundsen
29
*Example*
30
31
<pre>
32
; Prints a random line from the file 'file.txt'.
33
//echo $read(file.txt)
34
35
; Prints line '10' from the file 'file,txt.
36
//echo $read(file.txt, 10)
37
38
; Searches file 'file,txt for a line beginning with the text 'Hello World' and prints the text following the match value.
39
//echo $read(file.txt, s, Hello World)
40
41
; Searches file 'file.txt' for a line matching the wildmatch '*Hello World*' and prints it.
42
//echo $read(file.txt, w, *Hello World*)
43
</pre>