|
yorcadon Beginner
Joined: 11 Jun 2009 Posts: 16
|
Posted: Mon Mar 28, 2011 1:48 am
Providing line numbers while searching text files for specific text |
Basically I am looking for a way to be able to %read a file to search for certain things, but at the same time retrieve the line number in the file that it is in.
The goal is to be able to search several lines immediately before or after the line that comes up using %read.
On a side note, is it possible to use %read or similar commands on files using their directory without loading them via #FILE?
Thanks in advance for your help. |
|
|
|
Myrkul Wanderer
Joined: 21 Aug 2008 Posts: 85
|
Posted: Mon Mar 28, 2011 4:03 am |
[edit][/edit]
|
|
Last edited by Myrkul on Thu Apr 14, 2011 10:55 pm; edited 1 time in total |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Mon Mar 28, 2011 4:08 am |
1)the easiest way is perhaps to read in the file into a stringlist variable and doing your lookups there instead of at the point of the read-in. Stringlists, unless you set them to be sorted, retain their assignment order so it'd be a trivial thing to do a forwards/backwards lookup of nearby items.
2)I don't think so (should be easy and harmless enough to try, though, if it works and you know the targeted line is not blank then the return result should be that line's text.) It's something that goes way back to the days when flat-file formats were created (DOS, BASIC, etc), and it's been honored by more advanced technologies ever since. First you set up a pointer to the file, then you use that pointer when doing actions to said file. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
|
|