You are not logged in.

Unanswered posts



Important! This site has been replaced. All content here is read-only. Please visit our brand-new community at https://community.talend.com/. We look forward to hearing from you there!



#1 2017-04-04 23:52:56

talendtester
Member
253 posts

talendtester said:

Need to split a file on the 19th occurrence of the delimiter

Tags: [, java]

I have a file which is delimited by ";" for the columns at the far left side but then its variable on the right side.
Yes, I know its weird, but that is what they gave me to start with.
I want to split the file into part1 and part2 based on the 19th occurrence of the ";" delimiter.
I was thinking tInputDelimiter > tMap (regular expression) > tOutputDelimiter
Any idea how the regular expression should look?

Offline

#2 2017-04-06 13:22:46

TRF
Member
388 posts

TRF said:

Re: Need to split a file on the 19th occurrence of the delimiter

Hi,

Can't find a way with just a tMap but you can easily do it using a tJavaRow.

Here is a example:
mini_blob_20170406-0519.png

the data sample:
mini_blob_20170406-0520.png

the tJavaRow:

output_row.bigString = input_row.bigString;
output_row.part1 = "";
output_row.part2 = null;

if(input_row.bigString != null && StringHandling.COUNT(input_row.bigString, ";") >= 19) {
  String[] parts = input_row.bigString.split(";");
  for (int i = 0; i < 19; i++) {
    output_row.part1 = output_row.part1 + parts[i] + ";";
  }
    
  output_row.part2 = input_row.bigString.replace(output_row.part1, "");
  output_row.part1 = output_row.part1.substring(0, output_row.part1.length()-1);  
}
else {
  output_row.part1 = input_row.bigString;

the corresponding result:

[statistics] connected
.-----------------------------------------------------------------------------------+-------------------------------------------------------------------+-----------------.
|                                                                               tLogRow_11                                                                                |
|=----------------------------------------------------------------------------------+-------------------------------------------------------------------+----------------=|
|bigString                                                                          |part1                                                              |part2            |
|=----------------------------------------------------------------------------------+-------------------------------------------------------------------+----------------=|
|1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25                  |1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19                    |20;21;22;23;24;25|
|aaaa;bbb;cc;d;aaaa;bbb;cc;d;aaaa;bbb;cc;d;aaaa;bbb;cc;d;aaaa;bbb;cc;d;aaaa;bbb;cc;d|aaaa;bbb;cc;d;aaaa;bbb;cc;d;aaaa;bbb;cc;d;aaaa;bbb;cc;d;aaaa;bbb;cc|d;aaaa;bbb;cc;d  |
|1;2;3;4;5;6;7;8;9;10                                                               |1;2;3;4;5;6;7;8;9;10                                               |null             |
|1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;                                   |1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19                    |                 |
|                                                                                   |                                                                   |null             |
|null                                                                               |null                                                               |null             |
'-----------------------------------------------------------------------------------+-------------------------------------------------------------------+-----------------'

[statistics] disconnected

Regards,
TRF

Offline

#3 2017-04-06 17:06:19

talendtester
Member
253 posts

talendtester said:

Re: Need to split a file on the 19th occurrence of the delimiter

Thank you very much TRF!

Offline

Board footer

Talend Contributor Agreement - Talend Website Privacy Policy