Search for a word in a file

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
SURA
Premium Member
Premium Member
Posts: 1229
Joined: Sat Jul 14, 2007 5:16 am
Location: Sydney

Search for a word in a file

Post 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
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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?
-craig

"You can never have too many knives" -- Logan Nine Fingers
SURA
Premium Member
Premium Member
Posts: 1229
Joined: Sat Jul 14, 2007 5:16 am
Location: Sydney

Post 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
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
SURA
Premium Member
Premium Member
Posts: 1229
Joined: Sat Jul 14, 2007 5:16 am
Location: Sydney

Post by SURA »

Thanks Ray.
Post Reply