Format Output with Line Breaks

I have input like 1,2,3-7,8,9 How to generate output like below
1
2
3
4
5
6
7
8
9

Showing Answers 1 - 38 of 38 Answers

ahamed

  • May 12th, 2016
 

First use the normalize component, length is length(in.value) and in the transform write string_substring(in.value,(index*1)+1,1)..then you will get the output is
1
,
2
,
3
-
7
,
8
,
9
then you use the filter by expression and write is_valid(in.value) then the out put will be
1
2
3
7
8
9

  Was this answer useful?  Yes

Abhijit

  • May 12th, 2016
 

Use normalize to get the desired output.
In length function first replace - with , and then string_split and length_of function to take the length.
length_of(string_split(string_replace(in.data,"|",","),","))
then take a temp variable and assign value of string_split inside normalize and assign it through index
let string("")[] temp_data=string_split(string_replace(in.data,"|",","),",");
out.data::temp_data[index];

  Was this answer useful?  Yes

Sham

  • May 24th, 2016
 

Read the input file the use reformat to replace the special char with (,) then use sting split and find the max and min no. after that use normalize and use the length (max - min +1). In the normalize use the index and generate the no with min + index.

Eg: 5, 6-10, 11, 12
Out: 5 6 7 8 9 10 11 12

  Was this answer useful?  Yes

Swaraj Ranjan Sahu

  • Aug 5th, 2016
 

REFORMAT:
=======
let decimal(4) val1=0;
let decimal(4) val2=0;
let decimal(4) diff=0;
out :: reformat(in) =
begin
if (string_index(in.value,"-"))
begin
val1=string_substring(in.value,1,string_index(in.value,"-")-1);
val2=string_substring(in.value,string_index(in.value,"-")+1,string_length(in.value));
diff = (val2 - val1)+1;
end
else diff=1;
out.value::if (string_index(in.value,"-")>0) string_lrtrim(val1) else in.value;
out.diff::diff;
end;
NORMALIZE:
=======
out :: length(in) =
begin
out :: in.diff;
end;
out :: normalize(in, index) =
begin
out.value :: if (index==0) (decimal(""))in.value else string_lrtrim((decimal(""))in.value+index);
end;

  Was this answer useful?  Yes

Sankha

  • Dec 21st, 2016
 

Thanks for the answer Mr Swaraj

  Was this answer useful?  Yes

Ashutosh Prasad

  • Jan 30th, 2017
 

Use Normalize component to split records like this. Read the entire line with
delimiter.
In normalize use:
let string ("") [int] str_split = string_split(in.string_input);
out::length_of(string_split(in.string_input,",");
out::normalize(in)=
begin
out.str :: str_split[index];
end;

  Was this answer useful?  Yes

Somdev Sarkar

  • Jan 31st, 2017
 

Good answer Swaraj sir, however isnt there a easier way to do it - read each value in a separate field, instead as one string, and then use a metapivot?

  Was this answer useful?  Yes

Swaraj Ranjan Sahu

  • Feb 6th, 2017
 

Thank you Somdev. Actually the idea is to read the each field separately,and need to perform the logic wherever we have "-" in the value like (3-7). There we have to separate them and populate the gap between them like 3,4,5,6,7.

  Was this answer useful?  Yes

Abhijit

  • Aug 29th, 2017
 

You can use normalize function

Step 1: Find max and min value using rollup component
(Here MAx : 9 and min : 1)

Step 2: Give irollup output to normalize
Length (MAX-MIN)
Normalize
Min value +1

  Was this answer useful?  Yes

Ketan Khot

  • Nov 29th, 2017
 

You can use single normalize component. Use below code in normalize component.

let min = -1;
out :: length(in) =
begin
let string() [2] vec = allocate();
let diff = 1;

if(string_index(in.rec,-)
begin
vec = string_split(in.rec, -);
min = vec[0];
mix = vec[1];
diff = max - min;
end;
else
min = in.rec;
out :: diff;
end;

out :: normalise(in,index) =
begin
out :: min + index ;
end;

  Was this answer useful?  Yes

Anu

  • Jan 9th, 2020
 

String_split(String_replace(( re_get_match(in.input,"-")),","),",")
After that do string join

  Was this answer useful?  Yes

Neelima

  • Aug 25th, 2022
 

out :: reformat(in) = begin let int i = 0; let string("")[]dv = string_split(string_replace(in.line,"-",","),","); let int count=length_of(dv); let string("") res =""; for(i, i < count) begin let string("")value =string_split(string_replace(dv[i],"-",","),",")[0]; res = string_concat(res,value," "); end out.val :: (string("")) (decimal(""))res; end;

  Was this answer useful?  Yes

Ahmad Ali Quraishi

  • Jan 6th, 2024
 

Normalize:
out::length_of(in)
begin
let decimal("")[int] vec = allocate_with_default();
vec = if(string_index(in.id,"-")>0) string_split(in.id,"-") else vector_append(vec,in.id);
out :: if(length_of(vec)>1) vec[1]- vec[0] else 1;
end;
out :: normalize(in,index)
begin
let temp = if(index==0) vec[0];
out :: temp + index;
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