Any way to print differences of two text files?

97 views
Skip to first unread message

Allen Watson

unread,
Feb 26, 2024, 4:17:37 PM2/26/24
to BBEdit Talk
I love the ability to find the differences between two text files. I would really like to have a printed version of the result, showing the  differences, so that I could pass out a handout to students in my class. 

Is it possible somehow to print the differences? Just printing only prints the panel at the bottom, not the two side-by-side texts. A screen shot seems to lose the highlighting that shows the differences.

jj

unread,
Feb 27, 2024, 3:56:24 AM2/27/24
to BBEdit Talk
Hi Allen,

I don't know if this is possible with BBEdit alone.
But you could do it in a terminal with the help of command line utilities diff and aha, generating a colored HTML file.

Install Diffutils and Aha:

    % brew install diffutils
    % brew install aha


Run this command in Teminal with your files:
   
    % diff -y --color=always ~/Desktop/A.txt ~/Desktop/B.txt | aha --stylesheet > ~/Desktop/output.html

Within BBEdit with a differences window in the foreground with the help of Applescript:

tell application "BBEdit"

   if class of front window = differences window then

       set vFileA to POSIX path of ((file of first document of front window) as string)

       set vFileB to POSIX path of ((file of second document of front window) as string)

       set vCommand to "/opt/homebrew/bin/diff -y --color=always" & space & the quoted form of vFileA & space & the quoted form of vFileB & space & "| /opt/homebrew/bin/aha --stylesheet > ~/Desktop/output.html"

       do shell script (vCommand)

       do shell script "open ~/Desktop/output.html"

   end if

end tell


HTH


Jean Jourdain

Benjamin Irwin

unread,
Feb 27, 2024, 9:57:41 AM2/27/24
to BBEdit Talk
If you don't mind paying a one time purchase fee, I would recommend a great development tool called "Beyond Compare".  I have used it for many years monitoring changes(differences) in code.  It has many automation options.

Allen Watson

unread,
Feb 28, 2024, 10:20:19 PM2/28/24
to BBEdit Talk
I'll give this a try! Thank you.
Reply all
Reply to author
Forward
0 new messages