By Manny Fernandez

October 6, 2018

‘Diff’ Ways of Comparing Files

See what I did there?
As a security engineer, I am always doing comparisons of files to see where things have gone wrong. Here are some of the options I use depending on my scenario and environment.

For this example, I will use two files:

File 1

I am a cool day
He is an idiot
I am bald as a baby's butt
He is a bad hombre
123 456 789 101112

File 2

I am a cool day
He is an idiot
He is bald as a baby's butt
He is a bad hombre
789 101112 123 456

I use a Mac as my main computer for day-to-day activity. On my Mac, I have a great program I used to use in my Windows days, then I used it in my Linux days, and now on my Mac. It is called Beyond Compare

Beyond Compare is developed by Scooter Software.

In the Finder, you choose the file you want to compare and Select Left file for Compare

Then you choose the second file (the one you want to compare to the first file above) and then select Compare Files

Once you select the file, Beyond Compare will show the results.

The other option is the native ‘diff’ command.

diff file1.txt file2.txt

‘diff’ is the command followed by the name of the first and second file you want to compare.

 

The results are shown above. The output is a bit more complicated to understand. See the explanation below.

As you can see in the output, the first line show ‘3c3’ is telling you that line 3 need to be ‘changed’

to match line 3 of the second file.

The letter options are A=Add, C=Change, D=Delete

Also the ‘>’ denotes the first line content while the ‘<‘ denotes the second file. If you want to learn more, you can run ‘man diff’ from the command line.

The third option is ‘Diff checker’, a website.

The results are much clearer than the command line ‘diff’

Hope this helps.

Leave a comment

Your email address will not be published. Required fields are marked *

Recent posts