Brand new user to Knime and I'm not a developer - just need to merge two files...

Hi I’m a new user to Knime and I just want to merge two text files. The concatenate and joiner nodes are looking for columns in the dataset to join before merging. However, I’m not looking to join data from my tables. The first file has some text/header (is a string) info and the second file has a table with headers (tab delimited) - i just want to combine this into one file with the string at the top and the table at the bottom without any carriage return/empty rows. Simple merging of two files with different info and no joins.

Hi @herlo,
you could try to combine it while writing out the new file. In the CSV writer, there is the option “If exists: append”. With this you could first write the header to the new file, then add the table by appending the data to the existing file.

2 Likes

@herlo use the File Reader with fixed length and import as one column then append the two files to a CSV without column headers. Though I am not really sure what you want to use that for :slight_smile:

1 Like

I am also curious about the use-case here.

In addition to what is suggested above, you can use two Line Reader nodes, the Concatenate node and a CSV writer with the setting to ignore the column header.

HI @temesgen-dadi! And thank you so much for your help on this. Use case is to simply process files into a format that a 3rd party SW can understand for a bit of automation requirements. The end file needs to be in a tab delimited txt file format and have: (1) a command script at the top of the file for the the 3rd party SW to read and provide instructions and (2) the actual data in the table directly underneath the command line script for processing.

Users will generate the CSV with only the data table (including column headers). They drop this CSV in a network directory. Depending on the location of the file, KNIME will take the data table in that CSV and merge a specific command line script (script at the top, table at the bottom, no empty line spaces of course) and move it to another directory for the 3rd party SW to read and process. The variable is in the command line script and so I just have that in different files for merging with the data table in the CSV from the end user.

I’ve had experience with file processing in this manner with Pipeline Pilot in the past, but my current employer does not have a PP license and this use case itself does not justify such an investment. However, PP seems to be more straightforward with just handling and manipulating files. Seems like the KNIME nodes that are available are more geared towards datasets and relationships between those datasets, whereas I just want to automate merging, combining files and moving, renaming them without necessarily having to process the datasets themselves (there will be other use case for this of course that KNIME will be very helpful with). Thanks for your help!

Hi @daniela_digles , when using the CSV writer node, there is only one inport so not sure how I can combine the information in the two source files to write to this node. There is the Concatenate and Joiner nodes, but those seem to be looking for common data columns to join datasets from the different source files. The “If exists: append” options seems to produce the same result where only the info in the first file (the command script) gets written to the final output file and the actual data table is excluded. Below is an example of what I want to do. Take the info in the first two files and just merge together into the 3rd file. I would imagine this is such simple task, but maybe too simple?

You would use two different CSV writer nodes, but pointing to the same file (the name could be controlled by a variable if the file name should be different each time the workflow is run). To make sure the file is combined in the correct order, you can connect them with a variable connection.
But as @mlauber71 and @temesgen-dadi suggested, reading the files in a way that the data is included in only one column will allow to combine the data directly in KNIME with the concatenate node. In this case, you also don’t have to worry about the correct column delimiter symbol.

2 Likes

If the content of input file 1 is fixed, there is also the option to add a comment using the CSV writer node. See the screenshot below.

1 Like