Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
una_xikilla
Contributor
Contributor

Split a input file into multiple output files

Hello,

I have an input file and I want to make "n" output files using distinct value.

Eg:

Input File

HZARA 123

L123456HY

L98798676

L54354254

HCUSTO456

L98687687

L64746689

 

I need n different files based on distinct values in Col1 with "H".

 

HZARA.txt

L123456HY

L98798676

L54354254

 

HCUSTO.txt

L98687687

L64746689

 

Any help in this direction would be vey helpful. 0683p000009MPcz.png

Labels (2)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

Hi,

You cannot use "!=" operator for a string.

Try to import the attached job.


splitFiles.zip

View solution in original post

19 Replies
TRF
Champion II
Champion II

Add a tJavaRow to set a context variable with the filename as soon the first character is H. Add a tFilterRow to exclude rows with a H as a first character and finally call a child job to write rows in the output file according to the context variable.
una_xikilla
Contributor
Contributor
Author

Hi!

 

I'm learning Talend and i don't know how do that in the tJavaRow... 0683p000009MPcz.png

TRF
Champion II
Champion II

Here is the main job:

0683p000009Lqu4.png

- tFixedFlowInput is here to mimic your input file:

0683p000009Lr8m.png

- tJavaRow set the needed context variables (filename and line):

output_row.line = input_row.line;
output_row.type = input_row.line.substring(0, 1);

context.line = input_row.line;

if(output_row.type.equalsIgnoreCase("H"))
	context.filename = input_row.line.substring(1, 5);

- tFilterRow is here to exclude header lines from result:

0683p000009Lr6S.png

- tRunJob call the external job called "writer" (check the option "Transmit whole context" on this component to transmit the context variables "filename" and "line" you to define for both jobs)

 

Here is the external subjob "writer" :

0683p000009Lr0C.png

tFixedFlowInput is here to convert context variable "line" into a flow (required for the next component):

0683p000009Lr4O.png

- tFileOutputDelimited is here to write the flow into the current file (designed by filename context variable (check option "Append" to write at the end of the file):

0683p000009Lr1Y.png

 

It works.

una_xikilla
Contributor
Contributor
Author

Thank you! I'm trying 0683p000009MACJ.png

But I get error -> Error: Could not find or load main class. 0683p000009MApL.png

TRF
Champion II
Champion II

Did you ever run a job successfully with this installation?
If so, please share a capture of your design
una_xikilla
Contributor
Contributor
Author

Now it's ok.

But i can't choose "type" in the filter... why?

 

0683p000009Lr7p.png

TRF
Champion II
Champion II

Is the tFilter schema synchronized with the tJavaRow schema?
una_xikilla
Contributor
Contributor
Author

Hi,

 

I have synchronized tFilter schema with the tJavaRow schema but the field "type" not...

 

0683p000009Lr7Q.png

una_xikilla
Contributor
Contributor
Author

Hi again

 

I have create the out fields but the job says:

 

0683p000009Lr8s.png