|
178 | 178 | <description>
|
179 | 179 | <para>Read and write text file in character and line mode.</para>
|
180 | 180 | <para>Examples:</para>
|
181 |
| - <para/> |
182 | 181 | <para>Read mode (byte):</para>
|
183 |
| - <para> ;reads the entire content of the file.</para> |
184 |
| - <para> Set(foo=${FILE(/tmp/test.txt)})</para> |
185 |
| - <para> ;reads from the 11th byte to the end of the file (i.e. skips the first 10).</para> |
186 |
| - <para> Set(foo=${FILE(/tmp/test.txt,10)})</para> |
187 |
| - <para> ;reads from the 11th to 20th byte in the file (i.e. skip the first 10, then read 10 bytes).</para> |
188 |
| - <para> Set(foo=${FILE(/tmp/test.txt,10,10)})</para> |
189 |
| - <para/> |
| 182 | + <example title="Reads the entire content of the file"> |
| 183 | + same => n,Set(foo=${FILE(/tmp/test.txt)}) |
| 184 | + </example> |
| 185 | + <example title="Reads from the 11th byte to the end of the file (i.e. skips the first 10)"> |
| 186 | + same => n,Set(foo=${FILE(/tmp/test.txt,10)}) |
| 187 | + </example> |
| 188 | + <example title="Reads from the 11th to 20th byte in the file (i.e. skip the first 10, then read 10 bytes)"> |
| 189 | + same => n,Set(foo=${FILE(/tmp/test.txt,10,10)}) |
| 190 | + </example> |
190 | 191 | <para>Read mode (line):</para>
|
191 |
| - <para> ; reads the 3rd line of the file.</para> |
192 |
| - <para> Set(foo=${FILE(/tmp/test.txt,3,1,l)})</para> |
193 |
| - <para> ; reads the 3rd and 4th lines of the file.</para> |
194 |
| - <para> Set(foo=${FILE(/tmp/test.txt,3,2,l)})</para> |
195 |
| - <para> ; reads from the third line to the end of the file.</para> |
196 |
| - <para> Set(foo=${FILE(/tmp/test.txt,3,,l)})</para> |
197 |
| - <para> ; reads the last three lines of the file.</para> |
198 |
| - <para> Set(foo=${FILE(/tmp/test.txt,-3,,l)})</para> |
199 |
| - <para> ; reads the 3rd line of a DOS-formatted file.</para> |
200 |
| - <para> Set(foo=${FILE(/tmp/test.txt,3,1,l,d)})</para> |
201 |
| - <para/> |
| 192 | + <example title="Reads the 3rd line of the file"> |
| 193 | + same => n,Set(foo=${FILE(/tmp/test.txt,3,1,l)}) |
| 194 | + </example> |
| 195 | + <example title="Reads the 3rd and 4th lines of the file"> |
| 196 | + same => n,Set(foo=${FILE(/tmp/test.txt,3,2,l)}) |
| 197 | + </example> |
| 198 | + <example title="Reads from the third line to the end of the file"> |
| 199 | + same => n,Set(foo=${FILE(/tmp/test.txt,3,,l)}) |
| 200 | + </example> |
| 201 | + <example title="Reads the last three lines of the file"> |
| 202 | + same => n,Set(foo=${FILE(/tmp/test.txt,-3,,l)}) |
| 203 | + </example> |
| 204 | + <example title="Reads the 3rd line of a DOS-formatted file"> |
| 205 | + same => n,Set(foo=${FILE(/tmp/test.txt,3,1,l,d)}) |
| 206 | + </example> |
202 | 207 | <para>Write mode (byte):</para>
|
203 |
| - <para> ; truncate the file and write "bar"</para> |
204 |
| - <para> Set(FILE(/tmp/test.txt)=bar)</para> |
205 |
| - <para> ; Append "bar"</para> |
206 |
| - <para> Set(FILE(/tmp/test.txt,,,a)=bar)</para> |
207 |
| - <para> ; Replace the first byte with "bar" (replaces 1 character with 3)</para> |
208 |
| - <para> Set(FILE(/tmp/test.txt,0,1)=bar)</para> |
209 |
| - <para> ; Replace 10 bytes beginning at the 21st byte of the file with "bar"</para> |
210 |
| - <para> Set(FILE(/tmp/test.txt,20,10)=bar)</para> |
211 |
| - <para> ; Replace all bytes from the 21st with "bar"</para> |
212 |
| - <para> Set(FILE(/tmp/test.txt,20)=bar)</para> |
213 |
| - <para> ; Insert "bar" after the 4th character</para> |
214 |
| - <para> Set(FILE(/tmp/test.txt,4,0)=bar)</para> |
215 |
| - <para/> |
| 208 | + <example title="Truncate the file and write bar"> |
| 209 | + same => n,Set(FILE(/tmp/test.txt)=bar) |
| 210 | + </example> |
| 211 | + <example title="Append bar"> |
| 212 | + same => n,Set(FILE(/tmp/test.txt,,,a)=bar) |
| 213 | + </example> |
| 214 | + <example title="Replace the first byte with bar (replaces 1 character with 3)"> |
| 215 | + same => n,Set(FILE(/tmp/test.txt,0,1)=bar) |
| 216 | + </example> |
| 217 | + <example title="Replace 10 bytes beginning at the 21st byte of the file with bar"> |
| 218 | + same => n,Set(FILE(/tmp/test.txt,20,10)=bar) |
| 219 | + </example> |
| 220 | + <example title="Replace all bytes from the 21st with bar"> |
| 221 | + same => n,Set(FILE(/tmp/test.txt,20)=bar) |
| 222 | + </example> |
| 223 | + <example title="Insert bar after the 4th character"> |
| 224 | + same => n,Set(FILE(/tmp/test.txt,4,0)=bar) |
| 225 | + </example> |
216 | 226 | <para>Write mode (line):</para>
|
217 |
| - <para> ; Replace the first line of the file with "bar"</para> |
218 |
| - <para> Set(FILE(/tmp/foo.txt,0,1,l)=bar)</para> |
219 |
| - <para> ; Replace the last line of the file with "bar"</para> |
220 |
| - <para> Set(FILE(/tmp/foo.txt,-1,,l)=bar)</para> |
221 |
| - <para> ; Append "bar" to the file with a newline</para> |
222 |
| - <para> Set(FILE(/tmp/foo.txt,,,al)=bar)</para> |
| 227 | + <example title="Replace the first line of the file with bar"> |
| 228 | + same => n,Set(FILE(/tmp/foo.txt,0,1,l)=bar) |
| 229 | + </example> |
| 230 | + <example title="Replace the last line of the file with bar"> |
| 231 | + same => n,Set(FILE(/tmp/foo.txt,-1,,l)=bar) |
| 232 | + </example> |
| 233 | + <example title="Append bar to the file with a newline"> |
| 234 | + same => n,Set(FILE(/tmp/foo.txt,,,al)=bar) |
| 235 | + </example> |
223 | 236 | <note>
|
224 | 237 | <para>If <literal>live_dangerously</literal> in <literal>asterisk.conf</literal>
|
225 | 238 | is set to <literal>no</literal>, this function can only be executed from the
|
|
0 commit comments