Difference between revisions of "Fseek"

From Scriptwiki
Jump to: navigation, search
(little save due to many crashes of my pc)
 
Line 11: Line 11:
 
| l      || ''/fseek -l <name> <linenumber>''. Moves the pointer to the begin of the specified line.
 
| l      || ''/fseek -l <name> <linenumber>''. Moves the pointer to the begin of the specified line.
 
|-
 
|-
| n      || ''/fseek -n <name> <next line>''. Moves the pointer to the begin of the next line.
+
| n      || ''/fseek -n <name>''. Moves the pointer to the begin of the next line.
 
|-
 
|-
| w      || ''/fseek -w <name> <wildcard>''. Moves the pointer to the next occurence of a string matching  this wildcard from the current position of the pointer (see example below).
+
| w      || ''/fseek -w <name> <wildcard>''. Moves the pointer to the next occurrence of a string matching  this wildcard from the current position of the pointer (see example below).
 
|-
 
|-
| r      || ''/fseek -r <name> <regex>''. Moves the pointer to the next occurence of a string matching the regex.
+
| r      || ''/fseek -r <name> <regex>''. Moves the pointer to the next occurrence of a string matching the regex.
 
|}
 
|}
 +
 +
 +
== Example ==
 +
Let's imagine with have the following file "moo.txt" in our mircdir:
 +
This is my first line containing moo!
 +
This is just a senseless text file.
 +
mooooo
 +
thats the end.
 +
moo?
 +
We have opened this file using ''[[Fopen|/fopen]] moo moo.txt''
 +
 +
 +
/fseek -l moo 2
 +
This example would set the position of the pointer to the begin of the second line (infront of ''This is just a senseless text file.'').
 +
 +
 +
/fseek -n moo
 +
This example would set the pointer to the begin of the next line (infront of 'mooooo').
 +
 +
 +
/fseek -w moo moo*
 +
This example would move the pointer to the next occurrence of the word moo* after line three (that is line 5, ''moo?'' in our example file).
 +
 +
 +
/fseek -w moo moo*
 +
Now, this command would fail, as there is no other string containing ''moo'' after line 5.
 +
 +
 +
[[Category:File Handling]][[Category:Commands]]

Revision as of 00:17, 19 December 2005

Sets the read/write pointer to the specified position in the file.

/fseek <name> <position>


The following switches can also be used to move the file pointer:

Switch Meaning
l /fseek -l <name> <linenumber>. Moves the pointer to the begin of the specified line.
n /fseek -n <name>. Moves the pointer to the begin of the next line.
w /fseek -w <name> <wildcard>. Moves the pointer to the next occurrence of a string matching this wildcard from the current position of the pointer (see example below).
r /fseek -r <name> <regex>. Moves the pointer to the next occurrence of a string matching the regex.


Example

Let's imagine with have the following file "moo.txt" in our mircdir:

This is my first line containing moo!
This is just a senseless text file.
mooooo
thats the end.
moo?

We have opened this file using /fopen moo moo.txt


/fseek -l moo 2

This example would set the position of the pointer to the begin of the second line (infront of This is just a senseless text file.).


/fseek -n moo

This example would set the pointer to the begin of the next line (infront of 'mooooo').


/fseek -w moo moo*

This example would move the pointer to the next occurrence of the word moo* after line three (that is line 5, moo? in our example file).


/fseek -w moo moo*

Now, this command would fail, as there is no other string containing moo after line 5.