Data from 1 Column to be separated in Multiple Columns

Input file
col1
1
2
3
4
5
6
7
8
output file
col1 col2 col3 col4
1 2 3 4
5 6 7 8
How to achieve this?

Showing Answers 1 - 3 of 3 Answers

Nitin Patil

  • Apr 5th, 2018
 

created for 3 columns.
temp :: rollup(temp, in) =
begin
temp.rec :: if(temp.ind != 0)string_concat(temp.rec,"|",in.data) else temp.rec;
temp.ind :: temp.ind + 1;
end;
type temporary_type=record
decimal("") ind;
string("") rec;
end; /*Temporary variable*/
temp :: initialize(in) =
begin
temp.ind :: 0;
temp.rec :: in.data;

end;
out :: finalize(temp, in) =
begin
out.col1 :: (string_split(temp.rec,"|"))[0];
out.col2 ::(string_split(temp.rec,"|"))[1];
out.col3 :: (string_split(temp.rec,"|"))[2];
end;
out :: key_change(in1, in2) =
begin
out :: (next_in_sequence() % 3) ==0;
end;

  Was this answer useful?  Yes

Sai

  • May 24th, 2018
 

In this scenario, we need to take redefine component and provide the delimiter as "
",then will get this answer.
example:
record
decimal("|") number;
end;
then we have to change it into delimiter as
record
decimal("
") number;
end;

  Was this answer useful?  Yes

Avisek

  • May 28th, 2018
 

input file dml:
record
string("
") col1;
end
output file dml
record
string(",")col1;
string(",")col2;
string(",")col3;
string("
")col4;
end
use a rollup with key_change fn
let int count = 0;
let string("x01") val_a=;
let string("x01") val_b=;
let string("x01") val_c=;
out :: key_change(in1,in2) =
begin
count = count +1 ;
if ( count ==1 ) val_a=in1.col1;
if( count ==2 ) val_b=in1.col1;
if( count ==3) val_c=in1.col1;
if ( count >=4 ) count = 0 ;
out :: count == 0;
end;
out :: rollup(in) =
begin
out.col1=val_a;
out.col2=val_b;
out.col3=val_c;
out.col4=in.col1;
end;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions