DEV Community

Judy
Judy

Posted on

3 1 1 1 1

Compare two csv files #eg34

Here are two large, same-structure csv files A and B. Their primary keys are Name & Dept fields. The two have some different records.

Image description
Use Java to compare primary keys of the two files to find records that exist in A but that does not exist in B according to the key values.

Image description
Write the following SPL code:

Image description
T()function parses a csv file; @c option enables retrieving data from a file that does not fit into the memory. sortx() function sorts data in a cursor. merge() function merges two cursors; @d enables calculating the difference.

The logic of the above code can be also expressed in a single SPL statement:

=[T@c(""A.csv"").sortx(Name,Dept),T@c(""B.csv"").sortx(Name,Dept)].merge@d(Name,Dept).fetch()

Read How to Call a SPL Script in Java to find how to integrate SPL into a Java application.

Open source SPL source address

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (1)

Collapse
 
hanzla-baig profile image
Hanzla Baig

👍

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay