replace comma with next line character at even position

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
madhukar
Participant
Posts: 86
Joined: Fri May 20, 2005 4:05 pm

replace comma with next line character at even position

Post by madhukar »

Hi All,

i need to replace every even position comma (2, 4, 6...n) in the input row into a next line character.

Thanks in advance
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

I think this is a good case for a partial server job solution. Read the input as a single column and call up a BASIC routine like this:

Code: Select all

   EQUATE Comma TO ','
   EQUATE LF         TO CHAR(10)
   Ans = InString ;** assing the input value to the output string
   CommaCount = DCOUNT(Ans,Comma)
   IF MOD(CommaCount,2) <> 0 AND CommaCount THEN CommaCount -= 1
   FOR x = CommaCount TO 2 STEP -2
      Ans[Index(Ans,Comma,x),1] = LF
   NEXT x
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Are there commas in the data (in quoted character strings) or only as field delimiters?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

You can use translator from unix as well

Code: Select all

tr ',' '\n' < filename
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

How to do every second comma using tr command?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

If you have to go with OS then use awk. awk can get this done.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

ray.wurlod wrote:How to do every second comma using tr command?
Yeah, I didn't noticed this.
You can use

Code: Select all

tr ',' '\n' < filename | paste -d',' - -
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
madhukar
Participant
Posts: 86
Joined: Fri May 20, 2005 4:05 pm

Post by madhukar »

Thanks for all the answers

But i have to do it in datatsage and
input rows are of varying length i.e all rows will have even number of columns but number of columns is not same in each row and it is a comma delimited file
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

In this case, you need to either Basic Transformer to call the BASIC routine, or need to compose a C Routine.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Kumar - I am staying out of this one. The poster has gotten several viable options presented to him/her so far.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

madhukar wrote:But i have to do it in datatsage and ....
You have several solutions now. Pick your choice. Get as far as you can and if you have any problems, come back with what you have done and whats not working.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
madhukar
Participant
Posts: 86
Joined: Fri May 20, 2005 4:05 pm

Post by madhukar »

Thanks all
Post Reply