How can you split a csv file into multiple files based on the value of a column?

I need to find a way to split a csv file into multiple csv files based on the value of a particular column of my input csv file. I need the name of the newly generated csv files to be the value of that column as well.

For example:

input CSV file = 

Col1,Col2,Col3
1,2,Cat
1,3,Cat
2,4,Dog
2,5,Dog

I want to split by Col3 so I get the following table and file name:

---------------- File name = Cat.csv
Col1,Col2,Col3
1,2,Cat
1,3,Cat

 

---------------- File name = Dog.csv
Col1,Col2,Col3
2,4,Dog
2,5,Dog

Any way to do this with current Knime nodes or java snippet (I know minimal java)?

Thanks for any help.

The "Variables Loop (Data)" meta node should help to solve your problem. You have to enable expert mode to enable loop support (see http://tech.knime.org/faq#q5 for how to do that).

In the meta node's first port goes the input data, in its second port a list of all values of Col3 (val_col3) and the desired filename (val_filename) for each value. You can get this list for example with the "Group By"-node and append a column with the file names by the java snippet node. Within the meta node you can use a row filter to filter for val_col3 and write the filtered output to the corresponding file by configuring the CSV-writer to use the variable val_filename.

Hope that helps,
Dominik

Excellent. Works great. Thanks Dominik!

P.S. I appreciate the quick responses I get. You're a great  community.

Hi, i find this very similar to what i wished to do, however, i am stuck with getting the filename flow variable to my csv writer. Is it possible to share a sample workflow which i can learn from? I know this is an old thread, but i would really appreciate if anyone can help! thank you so much!