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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...