Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 207923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:46:44+00:00 2026-05-11T17:46:44+00:00

At regular intervals we are receiving CSV files from an external source that we

  • 0

At regular intervals we are receiving CSV files from an external source that we have little control over. These files are complete sets of current records; however, any records that have been deleted since the previous are not present. We would like to compare the two files and create a separate file of deleted records so we can do some additional processing on them. In an application in another area we have a commercial sort package (CoSort) that does this out of the box; however, we don’t have access to that here. The volumes aren’t that large, though, and it seems like this is something that standard or free tools might be able to handle quite easily. Ideally this would take the form of a Windows batch file, but Perl or awk solutions would be okay too. Example input files:

Previous File:

X_KEY,X_NAME,X_ATTRIBUTE
123,Name 123,ATT X
111,Name 111,ATT X
777,Name 777,ATT Y

Incoming File:

X_KEY,X_NAME,X_ATTRIBUTE
777,Name 777,ATT Y
123,Name 123,ATT CHANGED

Resulting File should be at a minimum:

111,Name 111

But if the attributes from the deleted records come through too, that is fine.

So far I have a batch file that uses freeware CMSort to sort the two files minus the header record to make it easier for some type of diff process:

REM Sort Previous File, Skip Header

C:\Software\CMSort\cmsort.exe /H=1 x_previous.txt x_previous_sorted.txt

REM Sort Incoming File, Skip Header

G:\Software\CMSort\cmsort.exe /H=1 x_incoming.txt x_incoming_sorted.txt

But the ‘compare and show only the missing records from the first file’ bit is eluding me. Part of the complexity is numerous attributes can change among the records that are left, so it isn’t a pure diff. However, it feels like a specialized diff command–one that is limited to checking just the key field, not the entire record. I can’t seem to get the syntax correct, though. Ideas? Record counts shouldn’t exceed 50k records.

Note: If this were SQL and the data were sitting in tables, we could use the EXCEPT operator but moving the data to the database in this case is not an option.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:46:44+00:00Added an answer on May 11, 2026 at 5:46 pm

    if i were to do this in perl I’d just use a couple of hashes,

    
    #!/usr/bin/perl -w                                                                                                           
    use strict;
    use warnings;
    
    my %orig; my %new; my %changed;
    
    open(F1,"<$ARGV[0]")||die"Couldn't open $ARGV[0]: $!\n";
    while(<F1>){
        chomp;
        @_ = split(/,/);
        $orig{$_[0]} = $_;
    }
    close(F1);
    
    open(F2,"<$ARGV[1]")||die"Couldn't open $ARGV[1]: $!\n";
    while(<F2>){
        chomp;
        @_ = split(/,/);
        if($orig{$_[0]}){
            if($orig{$_[0]} ne $_){
                $changed{$_[0]} = $orig{$_[0]}."||".$_;
            }
            delete $orig{$_[0]};
        }else{
            $new{$_[0]} = $_;
        }
    }
    close(F2);
    
    print "Deleted:\n";
    print map{$orig{$_}."\n"} sort {$b<=>$a} keys %orig;
    print "Added:\n";
    print map{$new{$_}."\n"} sort {$b<=>$a} keys %new;
    print "Changed:\n";
    print map{$changed{$_}."\n"} sort {$b<=>$a} keys %changed;
    

    assuming your text examples are in files f1.txt and f2.txt,

    
    kettle$ ./compare.pl f1.txt f2.txt
    
    Deleted:
    111,Name 111,ATT X
    Added:
    Changed:
    123,Name 123,ATT X||123,Name 123,ATT CHANGED
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 351k
  • Answers 351k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There is a refresh button. That should reload the DOM… May 14, 2026 at 7:20 am
  • Editorial Team
    Editorial Team added an answer It's possible your timer is the problem. You're invalidating it,… May 14, 2026 at 7:20 am
  • Editorial Team
    Editorial Team added an answer Turns out the particular font I was using was broken… May 14, 2026 at 7:20 am

Related Questions

I'm maintaining a legacy embedded device which interacts with the real world. Generally speaking,
At regular intervals, I receive a new release of a vendor's software, delivered as
I have an SVN repository where I have trunk and a branch. I intend
This one has been stumping me for a while. But I'm no expert. This

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.