Merge the CSV data represented by csvVariable into existing CSV content. The refColumns, if specified, is used to merge the 2 CSV content in such a way that the record of the same key(s) are merged together. For merging 2 CSV content based on multiple “key” columns, specified these columns (1) in the order of importance, and (2) separated by nexial.textDelim.

In general, there are 3 uses of this operation:

  1. merge two CSV content have no header
    In this case, records will be merged line-by-line with no regard to the data value.

    Example:

    [CSV( ${csv file to merge from} ) => parse store(merge_from)]
    ... ...
    [CSV( ${csv file to merge into} ) => parse(header=false) merge(merge_from) store(merge_into)]
    
    data variable snapshot
    csv file to merge into
    csv file to merge from
    merge into (AFTER merge)


    Script:
    script Note that in this example \(empty\) as the refColumns signifies that no shared column is between these 2 CSV files. Alternatively, omit the refColumns parameter entirely, as in merge(merge_from).

    Output:
    output

  2. merge two CSV content with headers, but without refColumns
    In this case, header exists in both CSV file, but they do not share any common column from the merge can be based on.

    Example:

    [CSV( ${csv file to merge from} ) => parse(header=true) store(merge_from)]
    ... ...
    [CSV( ${csv file to merge into} ) => parse(header=true) merge(merge_from) store(merge_into)]
    
    data variable snapshot
    csv file to merge into
    csv file to merge from
    merge into (AFTER merge)


    Script:
    script Note that passing \(empty\) as the refColumns signifies that no shared column is between these 2 CSV files. Alternatively, omit the refColumns parameter entirely, as in merge(merge_from).

    Output:
    output

  3. merge two CSV content with headers and share same refColumns
    In this case, header exists for both CSV data and they also share (at least) one common column whereby merge can use it to align the records.

    Example

    [CSV( ${csv file to merge from} ) => parse(header=true) store(merge_from)]
    ... ...
    [CSV( ${csv file to merge into} ) => parse(header=true) merge(merge_from,SSN) 
                                         store(merge_into)]
    
    data variable snapshot
    csv file to merge into
    csv file to merge from
    merge into (AFTER merge)


    Notice that the merged CSV is matching up the First Name and Last Name based on SSN, even though the order of these SSN are not the same.

    Script:
    script

    Output:
    output

  4. (more like 3a) merge two CSV content with headers and share multiple refColumns
    Similar to the above usage, Nexial also supports the merging of 2 CSV content with multiple key columns. As such, both CSV content will be sorted against the specified key columns before the content are merged together. Consider the following example:

    Script:
    script

    Output:
    In the first example (line 4), we are merging two CSV content using SSN, First Name, and Last Name. The output for this command looks like this:
    output

    In the second example (line 5), we mare merging the same two CSV content using Last Name, First Name and then SSN. Note that the key columns affected the sorting order:
    output

    Observe that the order of the merged CSV content is different than the previous output.