Write » History » Version 15
Per Amundsen, 02/16/2023 05:09 PM
| 1 | 1 | Per Amundsen | _Added in 1.9.0_ |
|---|---|---|---|
| 2 | |||
| 3 | 10 | Per Amundsen | */write [-cidnaiNmN l<line> s<text> w<wildcard> r</regex/>] <filename> [text]* |
| 4 | 1 | Per Amundsen | |
| 5 | 6 | Per Amundsen | Writes lines to a text file. |
| 6 | |||
| 7 | 1 | Per Amundsen | *Switches* |
| 8 | |||
| 9 | 15 | Per Amundsen | table(ktable). |
| 10 | |*Switch*|*Description*| |
||
| 11 | | -c | Clears the entire file before writing to it. | |
||
| 12 | | -i | Inserts the text at a given line instead of replacing it. | |
||
| 13 | | -d | Deletes the given or last line. | |
||
| 14 | | -n | Prevent adding [[$crlf]] at the end of the text. | |
||
| 15 | | -a | Appends the text to an existing line. | |
||
| 16 | | -lN | Line number for the line to write/modify/delete. | |
||
| 17 | | -sN | Operates on a line that matches the scanned <text>. | |
||
| 18 | | -wN | Operates on a line that matches the scanned <[[Scripting_Wildcards<notextile>|</notextile>wildcard]]> pattern. | |
||
| 19 | | -r | same as -w - but uses a [[Scripting_Regex<notextile>|</notextile>regular expression]] match. | |
||
| 20 | | -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. | |
||
| 21 | 9 | Per Amundsen | |
| 22 | 14 | Per Amundsen | *Parameters* |
| 23 | 1 | Per Amundsen | |
| 24 | 15 | Per Amundsen | table(ktable). |
| 25 | |*Parameter*|*Description*| |
||
| 26 | | <line> | The line number to find. | |
||
| 27 | | <text> | The text to scan. | |
||
| 28 | | <wildcard> | [[Scripting_Wildcards<notextile>|</notextile>Wildcard]] pattern to match. | |
||
| 29 | | </regex/> | [[Scripting_Regex<notextile>|</notextile>Regular expression]] pattern to match. | |
||
| 30 | | <filename> | The file name to manipulate. | |
||
| 31 | | [text] | The text to be written to the file. | |
||
| 32 | 1 | Per Amundsen | |
| 33 | *Example* |
||
| 34 | |||
| 35 | <pre> |
||
| 36 | alias example { |
||
| 37 | 8 | Per Amundsen | ; Create a file and add a few lines of text to it. |
| 38 | 1 | Per Amundsen | /write Example.txt this is a cool line |
| 39 | /write Example.txt hello there! |
||
| 40 | /write Example.txt text files are cool |
||
| 41 | |||
| 42 | 8 | Per Amundsen | ; Locate the line that starts with "hello" and insert the following text before it. |
| 43 | 1 | Per Amundsen | /write -is"Hello" Example.txt This will become line 2! |
| 44 | |||
| 45 | 8 | Per Amundsen | ; Delete line 1. |
| 46 | 1 | Per Amundsen | /write -dl1 Example.txt |
| 47 | } |
||
| 48 | </pre> |