Project

General

Profile

Write » History » Revision 14

Revision 13 (Per Amundsen, 12/30/2019 05:35 PM) → Revision 14/15 (Per Amundsen, 10/29/2020 02:38 AM)

_Added in 1.9.0_ 

 */write [-cidnaiNmN l<line> s<text> w<wildcard> r</regex/>] <filename> [text]* 

 Writes lines to a text file. 

 *Switches* 

 -c - Clears the entire file before writing to it. 
 -i - Inserts the text at a given line instead of replacing it. 
 -d - Deletes the given or last line. 
 -n - Prevent adding [[$crlf]] at the end of the text. 
 -a - Appends the text to an existing line. 
 -lN - Line number for the line to write/modify/delete. 
 -sN - Operates on a line that matches the scanned <text>. 
 -wN - Operates on a line that matches the scanned <[[Scripting_Wildcards|wildcard]]> pattern. 
 -r - same as -w - but uses a [[Scripting_Regex|regular expression]] match. 
 -mN - changes how [[$crlf]] are written to the end of a file, where N = 0 is the default behavior, N = 1 adds [[$crlf]] to end of file if it is not already there before writing a line, and N = 2 never adds [[$crlf]] to end of file before writing a line. *TODO* 

 *Parameters* 

 &lt;line&gt; - The line number to find. 
 &lt;text&gt; - The text to scan. 
 &lt;wildcard&gt; - [[Scripting_Wildcards|Wildcard]] pattern to match. 
 &lt;/regex/&gt; - [[Scripting_Regex|Regular expression]] pattern to match. 
 &lt;filename&gt; - The file name to manipulate. 
 [text] - The text to be written to the file. 

 *Example* 

 <pre> 
 alias example { 
   ; Create a file and add a few lines of text to it. 
   /write Example.txt this is a cool line 
   /write Example.txt hello there! 
   /write Example.txt text files are cool 
 
   ; Locate the line that starts with "hello" and insert the following text before it. 
   /write -is"Hello" Example.txt This will become line 2! 
 
   ; Delete line 1. 
   /write -dl1 Example.txt 
 } 
 </pre>