Page 1 of 1

finding words separated by spaces

Posted: Wed Aug 06, 2008 2:00 pm
by sravanthi
Hi,

I have a situation where i need to separte words:

Ex:

My input data looks like
CHICAGO CITY
ABC XYZ
A CNBC H.

I need to separate one word char(30) into 3 words.
col1,col2,col3
CITY,CHICAGO
XYZ,ABC
CNBC,A,H.

The length of these characters in each line are different and they are not uniform through out the file.

is there are method to identify spaces among words and when found pull first and so on

Please advice!

Posted: Wed Aug 06, 2008 2:04 pm
by chulett
Use COUNT to get the number of spaces, add 1, then use FIELD to pull each of them from your space delimited string. Or skip the COUNT if it is always three (max).

Posted: Wed Aug 06, 2008 2:14 pm
by sravanthi
chulett wrote:Use COUNT to get the number of spaces, add 1, then use FIELD to pull each of them from your space delimited string. Or skip the COUNT if it is always three (max). ...
Thank You

I will work using this and let you know how it goes :)

Posted: Wed Aug 06, 2008 3:16 pm
by ray.wurlod
What rule governs the order of words in the output?

Posted: Wed Aug 06, 2008 3:18 pm
by chulett
Hmmm... I thought it was just bass-ackwards order but closer examination of the evidence provided by the defense suggests otherwise.

Posted: Thu Aug 07, 2008 2:42 pm
by sravanthi
That's my requirement :(

Is there any method to select first word and then second word sepated by spaces.

abc xyz input

output should be:
col1 col2
abc xyz

And spaces between words are different for each words.

I have tried chulett's suggestion and was able to create some records.Please advice!

Posted: Thu Aug 07, 2008 2:47 pm
by chulett
Sure. Field(InputField," ",1,1) would get the first word from a space delimited InputField, Field(InputField," ",2,1) would get the second one. Field(InputField," ",1,2) would get the first and second "word" at once. Etc.

Posted: Fri Aug 08, 2008 11:33 am
by sravanthi
Thank You Chulett .

I was able to produce output file usinf field command. :D

Posted: Fri Aug 08, 2008 11:56 am
by chulett
Cool. Time to mark this as Resolved then, using the button at the top of the screen. :wink: