Getting Data In

How to compare two CSV files with multiple rows

vulnfree
Explorer

I am looking to compare two CSV files to output a change or addition.
Example:

File 1:
User Date Status
Dave 1/1 New
Linda 1/2 Old
Bob 1/3 Old

File 2:
User Date Status
Dave 1/1 Old
Dave 1/2 New
Linda 1/2 Old
Tony 1/8 New

If the user from File 1 matches File 2 and either row "date" and "status" have changed then output that information plus any new additions. Expected output

User Date Status
Dave 1/1 Old
Dave 1/2 New
Tony 1/8 New

0 Karma

dindu
Contributor

Hi,
You could use the "join " command to achieve functionality.
Please try the below functionality.Please let us know whether it worked.

index=source_file1 souretype=source_file1
|table Date,Status,User
|join type=inner User 
|[search index=source_file2 souretype=source_file2  
|eval Date_file2=Date,Status_file2=Status
|table Date_file2,Status_file2]
|eval match_date=if(Date_file2==Date,1,0),match_status=if(Status_file2==Status,1,0)
|where match_date=1 OR match_status=1
|table User,Date,Status
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...