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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] Split textfile into several files

Hi,

i have a input file with several blocks like this:

01[many numbers]
02 [many numbers]
02 [many numbers]
01[many numbers]
02 [many numbers]
02 [many numbers]
02 [many numbers]
02 [many numbers]
02 [many numbers]
01[many numbers]
02 [many numbers]
02 [many numbers]



Every block has one head row. The goal ist to get an output file for every block starting with 01:

file1.txt

01[many numbers]
02 [many numbers]
02 [many numbers]



file2.txt

01[many numbers]
02 [many numbers]
02 [many numbers]
02 [many numbers]
02 [many numbers]
02 [many numbers]




file3.txt

01[many numbers]]
02 [many numbers]
02 [many numbers]



Any ideas how to handle that?

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hi
You need to use tFlowToTerate to iterate each line one by one and set a dynamic output file name. For example:
tFileInputFullRow--main(row2)--tFlowToIterate--iterate--tjava-oncomponentok--tFixeFlowInput--main--tFileOutputDelimted

Define a context variable called blockID, integer type, set the default value as 0;
on tJava:
if(((String)globalMap.get("row2.line")).startsWith("01")){
context.blockID=context.blockID+1;
}

on tFixedFlowInput: get the current line, define one column with string type, set its value as:
(String)globalMap.get("row2.line")

on tFileOutputDelimited, set a dynamic file path, eg:
"D:/file/out"+context.blockID+".csv"

and check 'append' option.

View solution in original post

2 Replies
Anonymous
Not applicable
Author

Hi
You need to use tFlowToTerate to iterate each line one by one and set a dynamic output file name. For example:
tFileInputFullRow--main(row2)--tFlowToIterate--iterate--tjava-oncomponentok--tFixeFlowInput--main--tFileOutputDelimted

Define a context variable called blockID, integer type, set the default value as 0;
on tJava:
if(((String)globalMap.get("row2.line")).startsWith("01")){
context.blockID=context.blockID+1;
}

on tFixedFlowInput: get the current line, define one column with string type, set its value as:
(String)globalMap.get("row2.line")

on tFileOutputDelimited, set a dynamic file path, eg:
"D:/file/out"+context.blockID+".csv"

and check 'append' option.
Anonymous
Not applicable
Author

Thx shong!