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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...