Page 1 of 1

replace comma with next line character at even position

Posted: Tue Feb 13, 2007 5:52 am
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

Posted: Tue Feb 13, 2007 7:55 am
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

Posted: Tue Feb 13, 2007 2:27 pm
by ray.wurlod
Are there commas in the data (in quoted character strings) or only as field delimiters?

Posted: Tue Feb 13, 2007 6:21 pm
by kumar_s
You can use translator from unix as well

Code: Select all

tr ',' '\n' < filename

Posted: Tue Feb 13, 2007 7:33 pm
by ray.wurlod
How to do every second comma using tr command?

Posted: Tue Feb 13, 2007 8:34 pm
by DSguru2B
If you have to go with OS then use awk. awk can get this done.

Posted: Tue Feb 13, 2007 10:58 pm
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',' - -

Posted: Wed Feb 14, 2007 2:09 am
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

Posted: Wed Feb 14, 2007 2:44 am
by kumar_s
In this case, you need to either Basic Transformer to call the BASIC routine, or need to compose a C Routine.

Posted: Wed Feb 14, 2007 2:46 am
by ArndW
Kumar - I am staying out of this one. The poster has gotten several viable options presented to him/her so far.

Posted: Wed Feb 14, 2007 7:56 am
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.

Posted: Wed Feb 14, 2007 8:02 am
by madhukar
Thanks all