(archive 'newLISPer)

November 26, 2007

What’s the difference?

Filed under: newLISP — newlisper @ 16:40

Seen on a mailing list today:

Hi. I’m trying to figure out if it is at all possible to compare two files, and then output the list of missing lines in one file to a separate file.

Say, I have two documents, each containing a long list of items. The names of the documents are Document FULL and Document PARTIAL. I sort both alphabetically and do a difference between them.

I’d like to capture the list of items (rows) that exist in Document FULL but don’t exist in Document PARTIAL. How would I go about this?

This looks like a newLISP one-liner. But I hate one-liners for their ugliness and forced nature. So here’s a multi-line version:

(print "in the first but not the second: "  
(difference 
    (parse 
        (read-file 
            (string 
                (env "HOME" ) "/list1.txt" )) "\n"  0) 
    (parse 
        (read-file 
            (string 
                (env "HOME" ) "/list2.txt" )) "\n"  0)))

Leave a Comment »

No comments yet.

RSS feed for comments on this post.

Leave a comment

Create a free website or blog at WordPress.com.