(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)))
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: