Getting just the differences.

41 views
Skip to first unread message

Lee Hinde

unread,
Jan 8, 2016, 7:04:28 PM1/8/16
to bbe...@googlegroups.com
I'm doing a Find Differences between two files. I want to copy just the lines that are different, from both files, into a new document so I can send that to someone. 

Is there a way to do that?

Oliver Boermans

unread,
Jan 9, 2016, 1:33:51 AM1/9/16
to bbe...@googlegroups.com
Hi Lee,

this may work for you if you are happy sharing the whole line containing the difference and the two documents are mostly the same.

1. Make a copy of each file and remove any obvious unimportant difference between them. (Particularly line breaks)

2. Ensure the lines within each document are unique – prefix each line of both documents with a number

    Text > Add/Remove Line Numbers…
    ✓Insert – with other settings to your taste.

3. Copy and paste the contents of the first document into the end of the second.

4. Remove duplicate lines:

     Text > Process Duplicate lines
     ✓Matching All and ✓Delete duplicate lines

5. Sort lines to unite the different lines

     Text > Sort Lines…

Hope that helps

Cheers
Ollie

On 9 January 2016 at 10:34, Lee Hinde <leeh...@gmail.com> wrote:
I'm doing a Find Differences between two files. I want to copy just the lines that are different, from both files, into a new document so I can send that to someone. 

Is there a way to do that?

--
This is the BBEdit Talk public discussion group. If you have a
feature request or would like to report a problem, please email
"sup...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To post to this group, send email to bbe...@googlegroups.com.

Oliver Boermans

unread,
Jan 9, 2016, 1:36:04 AM1/9/16
to bbe...@googlegroups.com
Oops missed settings for Sort Lines…

✓ Numbers match by value
✓ Sorted lines replace selection

Enjoy

Christopher Stone

unread,
Jan 9, 2016, 10:25:20 AM1/9/16
to BBEdit-Talk
On Jan 08, 2016, at 18:04, Lee Hinde <leeh...@gmail.com> wrote:
> I'm doing a Find Differences between two files. I want to copy just the lines that are different, from both files, into a new document so I can send that to someone.
______________________________________________________________________

Hey Lee,

That's really simple from the command-line.

# Run from a BBEdit Worksheet:

diff "/Users/chris/Downloads/Test 01.txt" "/Users/chris/Downloads/Test 02.txt" | sed -En '/[<>]/p'
> Sometimes you feel like a nut.
> Testarossa!
< The ravenous wolf chased Little Red Riding Hood up a tree.
< Nervous nellies eshew the command-line.
> Some more text to test with.

The greater-than and less-than symbols point to which file the line shows up in.

The different lines are in order from top to bottom.

From there it's easy to massage the text into the form you want.

Here's an example script (run using menu #! > Run in BBEdit):

#! /usr/bin/env bash

FILE01="/Users/myUserName/Downloads/Test 01.txt";
FILE02="/Users/myUserName/Downloads/Test 02.txt";

diffText=$(diff "$FILE01" "$FILE02" | sed -En '/[<>]/p');

file01Lines=$(sed -En '/^</p' <<< "$diffText");
file02Lines=$(sed -En '/^>/p' <<< "$diffText");

file01Lines=$(sed -E 's!^[<][[:blank:]]*!!' <<< "$file01Lines");
file02Lines=$(sed -E 's!^[>][[:blank:]]*!!' <<< "$file02Lines");

echo $FILE01;
echo "";
echo "$file01Lines"
echo "";
echo $FILE02;
echo "";
echo "$file02Lines"

# OUTPUT

================================================================================
Jan 09, 2016, 09:21:42
untitled text 345
--------------------------------------------------------------------------------
/Users/chris/Downloads/Test 01.txt

The ravenous wolf chased Little Red Riding Hood up a tree.
Nervous nellies eshew the command-line.

/Users/chris/Downloads/Test 02.txt

Sometimes you feel like a nut.
Testarossa!
Some more text to test with.

--
Best Regards,
Chris

Lee Hinde

unread,
Jan 9, 2016, 1:23:04 PM1/9/16
to bbe...@googlegroups.com
Thanks for the suggestions!
Reply all
Reply to author
Forward
0 new messages