# Normalize denormalized CSV

**URL:** <https://forum.cloverdx.com/t/normalize-denormalized-csv/456>\
**Category:** CloverDX Platform\
**Created:** [December 15, 2008, 12:00am UTC](https://forum.cloverdx.com/t/normalize-denormalized-csv/456 "2008-12-15T00:00:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anmack](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.cloverdx.com/anmack/32/74_2.png) [@anmack](https://forum.cloverdx.com/u/anmack)\
**Post date:** [December 15, 2008, 12:00am UTC](https://forum.cloverdx.com/t/normalize-denormalized-csv/456/1 "2008-12-15T00:00:00Z")

</div>

Hello,

i try to extract some data from a denormalized CSV-file.

Example:

```auto
name_first|name_last|data1,data2,data3,|\n

```

I want to normalize the data to this form:

```auto
name_first name_last data1
name_first name_last data2
name_first name_last data3

```

i don’t know exactly how to use the NORMALIZER tool. 😢

Can you help me …?!

Greetings from germany

---

<div class="post-metadata">

**Author:** ![dpavlis](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@dpavlis](https://forum.cloverdx.com/u/dpavlis)\
**Post date:** [December 15, 2008, 9:39pm UTC](https://forum.cloverdx.com/t/normalize-denormalized-csv/456/2 "2008-12-15T21:39:52Z")

</div>

You have to “implement” these two functions inside Normalizer component (assuming you will use CTL):

```auto
function count() {
   return 3;
}

```

Function count() is called once for each input row/record. Its task is to tell component how many times it should call “transform()” function on input row. Each time, counter (counting from 0…) is passed into “transform()” and it has to produce one output record.

```auto
function transform(idx) {
                 $0.name_first:=$0.name_first;
                 $0.name_last:=$0.name_last;
                 switch (idx) {
                    case 0: $0.data=$0.data1;
                    case 1: $0.data=$0.data2;
                    case 2: $0.data=$0.data3;
                  }
 }

```

I assume that output metadata of Normalizer contains 3 fields (first\_name,last\_name,data).

---

<div class="post-metadata">

**Author:** ![anmack](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.cloverdx.com/anmack/32/74_2.png) [@anmack](https://forum.cloverdx.com/u/anmack)\
**Post date:** [December 16, 2008, 7:45pm UTC](https://forum.cloverdx.com/t/normalize-denormalized-csv/456/3 "2008-12-16T19:45:15Z")

</div>

Thanks a lot for the fast answer.

I tried it, but the there is an other problem. The number of data in the denormalized value varies between 1 and 10.

In the count function i try to get the number of data values and in the transform function i try to cut out the related data.

```auto
function count() {
	int i = 0;
	int pos = 0;
	string myString = $0.M_ACTORS;
	while( pos = index_of( myString,",",pos ) ){
		i++;
		pos++;
	}
	return i;
}

function transform(idx) {
	int posStart = 0;
	int posEnd = 0;
	int i = 0;
	for( i; i < idx; ++i) {
		posStart = posEnd;
		posEnd = index_of( $0.M_ACTORS,",",posStart+1 );
	}
	$0.M_NAME := $0.M_NAME;
	$0.M_STUDIO := $0.M_STUDIO;
	$0.M_ACTOR := substring( $0.M_ACTORS,posStart,posEnd-posStart );
	$0.M_CLASS := $0.M_CLASS;
}

```

Do you have any experience in this problem ?

Andreas Mack

---

<div class="post-metadata">

**Author:** ![dpavlis](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@dpavlis](https://forum.cloverdx.com/u/dpavlis)\
**Post date:** [December 16, 2008, 9:07pm UTC](https://forum.cloverdx.com/t/normalize-denormalized-csv/456/4 "2008-12-16T21:07:40Z")

</div>

You may do something like this:

```auto

list values;

function count() {
   trunc(values);
   values=split($0.M_ACTORS,",");
   return length(values);
}

function transform(idx) {
   $0.M_NAME := $0.M_NAME;
   $0.M_STUDIO := $0.M_STUDIO;
   $0.M_ACTOR := values[idx]; 
   $0.M_CLASS := $0.M_CLASS;
}

```

[/code]

---

<div class="post-metadata">

**Author:** ![anmack](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.cloverdx.com/anmack/32/74_2.png) [@anmack](https://forum.cloverdx.com/u/anmack)\
**Post date:** [December 17, 2008, 6:41pm UTC](https://forum.cloverdx.com/t/normalize-denormalized-csv/456/5 "2008-12-17T18:41:18Z")

</div>

Thanks a lot … it works ! :lol:
