[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Diff: obtain only the different lines of the newest file
From: |
Bob Proulx |
Subject: |
Re: Diff: obtain only the different lines of the newest file |
Date: |
Thu, 12 Aug 2010 01:44:35 -0600 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
Kimahri Ronso wrote:
> My question is about the diff command.
>
> I have 2 files containing almost the same information with around 70.000
> records.
>
> What I would like to know is if there is a possibility to obtain only the
> different lines from the second file without anything else.
Instead of using 'diff' you might find 'comm' more the right tool
there.
Compare sorted files FILE1 and FILE2 line by line.
With no options, produce three-column output. Column one contains
lines unique to FILE1, column two contains lines unique to FILE2, and
column three contains lines common to both files.
-1 suppress lines unique to FILE1
-2 suppress lines unique to FILE2
-3 suppress lines that appear in both files
Here is an example. Given:
$ cat /tmp/a
one
two
three
$ cat /tmp/b
one
two
three
four
five
six
Then:
$ comm -13 /tmp/a /tmp/b
four
five
six
> I just need to know the content of the changed lines in the newest file.
For that you would need to determine the newest file first and then
handle it appropriately. Something like this, untested:
if [ $(stat --format %Y /tmp/a) -lt $(stat --format %Y /tmp/b) ]; then
comm -13 /tmp/a /tmp/b
else
comm -13 /tmp/b /tmp/a
fi
The stat with %Y emits the modification time as an integer number of
seconds and that is compared to determine the newest file.
Bob