Project

General

Profile

$read » History » Revision 2

Revision 1 (Per Amundsen, 08/14/2015 01:30 PM) → Revision 2/3 (Per Amundsen, 02/23/2023 07:22 PM)

_Added in 1.9.0_ 

 *$read(filename, [ntswrp], [matchtext], [N])* 

 Returns a single line of text from a file. 

 _See also [[$readn]]._ 

 *Parameters* 

 table(ktable). 
 |*Parameter*|*Description*| 
 | filename | - Filename to read. | 
 | [ntswrp] | - (optional) | 
 | [matchtext] | Matchtext to search. (optional) | <pre> 
 | [N] | The Nth line. | 

 *Options* 

 table(ktable). 
 |*Option*|*Description*| 
 | n | - Don't evaluate any identifiers in the line. | 
 | t | - Treat the first line as a plain text, even if it's a number. | 
 | s | - Search for matchtext. | 
 | w | - Search for matchtext as a wildmatch. | 
 | r | - Search for matchtext as a regular expression. | 
 | p | - Treat command <notextile>|</notextile> | separators as such instead of as plain text. | 
 </pre> 

 [matchtext] - Matchtext to search. (optional) 
 [N] - The Nth line. 

 *Example* 

 <pre> 
 ; Prints a random line from the file 'file.txt'. 
 //echo $read(file.txt) 

 ; Prints line '10' from the file 'file,txt. 
 //echo $read(file.txt, 10) 

 ; Searches file 'file,txt for a line beginning with the text 'Hello World' and prints the text following the match value. 
 //echo $read(file.txt, s, Hello World) 

 ; Searches file 'file.txt' for a line matching the wildmatch '*Hello World*' and prints it. 
 //echo $read(file.txt, w, *Hello World*) 
 </pre>