Application To Compare Two Text Files

When you launch the application, it asks you to select two files that you want to compare. Just select the files, choose file comparison type (Text or Binary) and click Compare. Upon click, you will be taken to the application’s main interface, which offers a dual-pane view to check the differences. How to compare two text files using Notepad. These instructions have been written for Notepad v6.3. Open Notepad. Click on the ‘Plugins’ menu at the top of the screen. Click on ‘Plugin Manager’ then ‘Show Plugin Manager’. A list of available plugins will appear – if it does not you need to check your Internet connection.

This guide will show you how to use Linux to compare two files and output their difference to the screen or to a file.

You do not need to install any special software in order to compare files using Linux but you do need to know how to open a terminal window.

As the linked guide shows there are many ways to open a terminal window using Linux. The simplest is to press the CTRL, ALT and T keys at the same time.

Compare two text files onlineApplication To Compare Two Text Files

Creating The Files to Compare

Compare Two Text Files Online

In order to follow along with this guide create a file called file1, and enter the following text:

You can create a file by following these instructions:

  1. Open the file by typing the following command:

  2. Type the text into the nano editor.

Now create another file called 'file2' and enter the following text:

You can create a file by following these instructions:

  1. Open the file by typing the following command:

  2. Press CTRL and O to save the file.

  3. Press CTRL and X to exit the file.

How to Compare Two Files Using Linux

The command used within Linux to show the differences between 2 files is called the diff command.

The simplest form of the diff command is as follows:

If the files are the same then there will be no output when using this command, however, as there are differences you will see output similar to the following:

Initially, the output may seem confusing but once you understand the terminology it is fairly logical.

You can see that the differences between the 2 files are as follows:

  • The second file only has three lines whereas the first file has 4.
  • The second file says '1 green bottle' on the third line whereas the first file says 'one green bottle'
  • The second file says 'there'd' instead of 'there would' on the final line

The output from the diff command shows that between lines 2 and 4 of the first file and lines 2 and 3 of the second file there are differences.

It then lists the lines from 2 to 4 from the first file followed by the 2 different lines in the second file.

How to Just Show If the Files Are Different

If you just want to know if the files are different and you aren't interested in which lines are different you can run the following command:

If the files are different the following will be displayed:

Application To Compare Two Text Files Windows 10

If the files are the same then nothing is displayed.

How to Show a Message If the Files Are the Same

When you run a command you want to know that it has worked correctly, so you want a message to be displayed when you run the diff command regardless as to whether the files are the same or different

In order to achieve this requirement using the diff command, you can use the following command:.

Now if the files are the same you will receive the following message:

How to Produce the Differences Side by Side

If there are lots of differences then it can very quickly become confusing as to what the differences actually are between the two files.

You can change the output of the diff command so that the results are shown side by side. In order to do this run the following command:

The output for the file uses the | symbol to show a difference between the two lines, a < to show a line that has been removed and a > to show a line that has been appended.

Interestingly if you run the command using our demonstration files then all the lines will show as different except for the last line of file 2 which will be shown as having been deleted.

Restricting the Column Widths

When comparing two files side by side it can be hard to read if the files have lots of columns of text.

Simple Java Program To Compare Two Text Files

To restrict a number of columns use the following command:

How to Ignore Case Differences When Comparing Files

If you want to compare two files but you don't care whether the case of the letters is the same between the two files, then you can use the following command:

How to Ignore Trailing White Space at the End of a Line

If when comparing the files you notice loads of differences and the differences are caused by white space at the end of the lines you can omit these as showing up as changes by running the following command:

Compare 2 text files

Compare 2 Text Files

How to Ignore All White Space Differences Between Two Files

If you are only interested in the text in a file and you don't care whether there are more spaces in one than the other you can use the following command:

How to Ignore Blank Lines When Comparing Two Files

If you don't care that one file may have extra blank lines in it then you can compare the files using the following command:

Summary

You can find more information by reading the manual for the diff command.

The diff command can be used in its simplest form to just show you the differences between 2 files but you can also use it to create a diff file as part of a patching strategy as shown in this guide to the Linux patch command.

Another command you can use to compare files is the cmp command as shown by this guide. This compares files byte by byte.