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:
-
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:
Note that in this example
\(empty\)
as therefColumns
signifies that no shared column is between these 2 CSV files. Alternatively, omit therefColumns
parameter entirely, as inmerge(merge_from)
.Output:
-
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:
Note that passing
\(empty\)
as therefColumns
signifies that no shared column is between these 2 CSV files. Alternatively, omit therefColumns
parameter entirely, as inmerge(merge_from)
.Output:
-
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 onSSN
, even though the order of theseSSN
are not the same.Script:
Output:
-
(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:
Output:
In the first example (line 4), we are merging two CSV content usingSSN
,First Name
, andLast Name
. The output for this command looks like this:
In the second example (line 5), we mare merging the same two CSV content using
Last Name
,First Name
and thenSSN
. Note that the key columns affected the sorting order:
Observe that the order of the merged CSV content is different than the previous output.