Page 1 of 1

Search for a word in a file

Posted: Wed Apr 06, 2011 6:55 am
by SURA
Hi All

I wish to search for a word in a file using BASIC language.

I can open the file.

Code:

OpenSeq FILENAME To fOpened
ReadSeq Record From fOpened


But not sure how to search for a word inside the file. Sorry now only i started to work with BASIC Language.

For example:

SUN
MOON
EARTH

I know what i need to search for the word "MOON" in the file, but not sure how to do it.

It will be great if any one can guide me in this.

Thanks
DS User

Posted: Wed Apr 06, 2011 7:08 am
by chulett
Is your search target always on its own as in your example? If so, then it seems a simple equality check is all you need. If the 'word' is buried in a larger string, then a function like Index() or Matches() can be used to detect a substring within a string.

Once you find it, then what?

Posted: Wed Apr 06, 2011 10:46 pm
by SURA
Hi craig

Thanks for your reply.

Sorry, I may not explain properly.

I am trying to implement a logic in which i need to find the specified String "I will pass it as Param" is present in the file or not?

Need is like X = cat filename | grep "MOON"

SUN
MOON
EARTH

If i write a code like below,

OpenSeq FILENAME To fOpened
ReadSeq Record From fOpened

now the first line is in Record. How to move to next line, making it in loop.

Or is there is any way to search for a specific word like cat filename | grep "MOON"

Please guide me.

Thanks
DS User

Posted: Thu Apr 07, 2011 12:09 am
by ray.wurlod
Yes, the Index() function.

Code: Select all

Counter = 0
Value = DSGetParamInfo(hJob, "jpSearchString", DSJ.PARAMVALUE)
Loop
While ReadSeq Record From fOpened
   Counter += (Index(Record, Value, 1) > 0)
Repeat
Ans = Counter

Posted: Thu Apr 07, 2011 1:01 am
by SURA
Thanks Ray.