Comparison of 2 files. Utilities for quick document comparison

Comparison of 2 files. Utilities for quick document comparison

31.12.2021

Sometimes it becomes necessary to compare several files with each other. This may be useful when analyzing the difference between several versions of a configuration file, or simply to compare different files. In Linux, there are several utilities for this, both for working through the terminal and in the graphical interface.

In this article, we will take a look at how Linux file comparison is performed. Let's take a look at the most useful methods, both for the terminal and in graphical mode. Let's first look at how to compare a linux file using the diff utility.

The diff linux utility is a program that runs in console mode. Its syntax is very simple. Call the utility, transfer the necessary files, and also set options, if necessary:

$ diff options file1 file2

More than two files can be transferred if needed. Before moving on to examples, let's take a look at the utility options:

  • -q- display only differences between files;
  • -s- display only matching parts;
  • -With- display the required number of lines after matches;
  • -u- display only the required number of lines after the differences;
  • -y- output in two columns;
  • -e- output in ed format of the script;
  • -n- output in RCS format;
  • -a- compare files as text, even if they are not text;
  • -t- replace tabs with spaces in the output;
  • -l- split into pages and add paging support;
  • -r- recursive folder comparison;
  • -i- ignore case;
  • -E- ignore changes in tabs;
  • -Z- ignore spaces at the end of the line;
  • -b- ignore spaces;
  • -B- ignore empty lines.

These were the main options of the utility, now let's look at how to compare Linux files. In the output of the utility, in addition to, directly, displaying changes, it displays a line in which it is indicated in which line and what was done. For this, the following symbols are used:

  • a- added;
  • d- removed;
  • c- changed.

In addition, lines that differ will be indicated by the symbol<, а те, которые совпадают - символом >.

Here are the contents of our test files:

Now let's do a diff file comparison:

diff file1 file2

As a result, we get the line: 2,3c2,4. It means that lines 2 and 3 have been changed. You can use options to ignore case:

diff -i file1 file2

It can be concluded in two columns:

diff -y file1 file2

And with the -u option, you can create a patch, which can then be applied to the same file by another user:

diff -u file1 file2

To process multiple files in a folder, it is convenient to use the -r option:

diff -r ~ / tmp1 ~ / tmp2

For convenience, you can redirect the utility output directly to a file:

diff -u file1 file2> file.patch

As you can see, everything is very simple. But not very convenient. It is more pleasant to use graphical tools.

Comparing Linux files using the GUI

There are some great tools for comparing files on linux in a GUI. You can easily figure out how to use them. Let's take a look at a few of them:

1. Kompare

Kompare is a graphical diff utility that allows you to find differences in files as well as combine them. It is written in Qt and designed primarily for KDE. Here are its main features:

  • Support for multiple diff formats;
  • Support linux file and directory comparison;
  • Support for viewing diff files;
  • Customizable interface;
  • Create and apply patches to files.

2. DiffMerge

DiffMerge is a cross-platform file comparison and merging software. Allows you to compare two or three files. On-the-fly line editing is supported.

Peculiarities:

  • Support for comparing directories;
  • Integration with file viewer;
  • Customizable.

3. Meld

It is an easy tool for comparing and merging files. It allows you to compare files, directories, and perform version control functions. The program was created for developers and has the following features:

  • Comparison of two and three files;
  • Using custom types and words;
  • Auto merge mode and actions with text sides;
  • Support for Git, Mercurial, Subversion, Bazar and more.

4. Diffuse

Diffuse is another popular and fairly simple tool for comparing and merging files. It is written in Python. Two main features are supported - file comparison and version control. You can edit files while watching. Main functions:

  • Syntax highlighting;
  • Keyboard shortcuts for easy navigation;
  • Unlimited undo support;
  • Unicode support;
  • Supports Git, CVS, Darcs, Mercurial, RCS, Subversion, SVK and Monotone.

5.XXdiff

XXdiff is a free and very powerful file comparison and merging tool. But the program has several drawbacks. This is the lack of Unicode support and file editing.

Peculiarities:

  • Superficial or recursive comparison of one or two files and directories;
  • Highlighting differences;
  • Interactive association;
  • Support for external comparison tools such as GNU Diff, SIG Diff, Cleareddiff and more;
  • Scripting extensibility;
  • Customizability.

6.KDiff3

KDiff3 is another great, free file comparison tool for the KDE desktop environment. It is included in the KDevelop suite of programs and runs on all platforms, including Windows and MacOS. It is possible to compare two linux files for two or three, or even compare directories. Here are the main features:

  • Displaying differences line by line and character by character;
  • Auto merge support;
  • Handling merge conflicts;
  • Unicode support;
  • Displaying differences;
  • Support for manual alignment.

conclusions

In this article, we looked at how to compare linux files using the terminal, how to create patches, and also did a small overview of the best graphical utilities for comparing files. What comparison tools do you use? Write in the comments!

Compare is one of the most useful plugins out there. And if you have a need to compare 2 files in Notepad ++, compare is what you need.

In order to compare files in notepad ++, check if the plugin is installed. To do this, open the plugins tab. If it is not installed, go to the Plugin Manager: Plugins - Plugin Manager - Compare - Install. After installing the plugin, the editor will restart.

Comparing files in notepad ++ is quite simple: open the two files you want to compare, press Ctrl + Alt + 1 or perform an action in the menu.

After that, we have three sections of the window: the first file, the second and Compare NavBar in which the differences in the documents, if any, are graphically marked. Thus, we compared two files editor Notepad ++.

In notepad ++, it turned out to be quite simple to compare two files, as you can see the notepad ++ editor performs line-by-line comparison of files with highlighting of lines with different code. For me, as for many webmasters, this editor is the best.

Free solutions

Synchronizing data requires both time and skill from programmers, system administrators. However, the right toolbox is no less important. Version control, working with projects, backing up, merging and visual comparison of files - this is not a complete list of tasks one way or another related to synchronization.

The guide includes 10 programs that can be called universal in many respects: they are not tied to a specific service or application, they allow you to perform the above (and less specialized) tasks not only through the graphical interface, but also in the command line mode.

The comparison criteria are as follows:

  • Interface: support for display modes, saving sessions, customization of the toolbar, columns
  • Text editor functionality, working with source code
  • Merge and sync methods, 3-way comparison capability
  • Export reports, create patches (diff)
  • Additional functions: integration with third-party applications, support for extensions, protocols, etc.

SmartSynchronize

SmartSynchronize is a cross-platform program for comparing data, directory structures and their contents. In fact, the program is free for non-commercial use, however, a single-user license costs 39 USD.

The comparison modes are presented in the welcome window of the program. In addition to the file selection dialog, you can view the history and select a saved profile. Also, filters are configured in the Preferences: file filters - to filter files by name and extension, and directory filters - allow you to create a list of exclusions.

To compare files, a side-by-side two-pane mode is used with synchronous scrolling of the contents of both panels. SmartSynchronize notation is limited, but thanks to linking lines, compare and merge operations are very intuitive. SmartSynchronize specifies where and in which direction a section will be added from one file to another. Inserting text is done with one click, eliminating the need for a context menu.

Document encoding and syntax can be defined manually, syntax highlighting for many programming and markup languages, line numbering, and other editorial features inherent in IDEs are provided.

In general, SmartSynchronize is highly configurable, but all settings are divided into different sections of the menu, which takes some getting used to. There are not enough display modes, toolbar settings.

In the directory comparison mode, a list of files and the status for each of them are displayed; a preview is available in the lower part of the window. The comparison method - by content or only by size and time - is defined in the Edit → Preferences settings. The number of information columns (file type, date) cannot be increased, although the existing ones can be disabled.

SmartSynchronize implements both one-way data merge with left or right sides, as well as regular synchronization. The configuration can be saved for later loading by taking a snapshot of the file structure. As the developers explain, the program does not recognize file attributes, so there is no point in using it as a backup utility. Working with archives is also not provided, as well as with remote directories.

In addition to the above, there is an additional, three-way merge method - 3-Way-Merge, which allows you to merge differences between multiple versions of files, and each of the three documents can be edited independently of each other.

Comparison functions are undoubtedly useful for version control programmers. Therefore, in conclusion, it is worth referring to an alternative solution of the same company -. The program is a CVS client with integrated SmartSynchronize toolkit.

Summary... SmartSynchronize offers a pretty good toolkit for working with files and directories, which in some places is not configurable and does not go beyond the basic capabilities.

[+] Trilateral merge
[+] Convenient text editor
[-] Lack of documentation
[-] Inability to synchronize remote directories and archives

WinMerge

WinMerge is a program for comparing and merging files and directories in Windows. It can be used as a standalone tool or in conjunction with projects. WinMerge has a built-in text editor with support for programming languages, highlighting and line numbering.

There are two modes of working with data, combined into a dialog for selecting files and folders. When comparing, there are two types of filters available: file filters and string filters. This allows you to use various add-ins and operate with regular expressions, filtering out the necessary data types when comparing.

In the file comparison mode, the window displays both files, on the left and right sides. A map (“Locations”) is provided for easy navigation through the content. The lines that have differences are highlighted in color, you can also see them in the "Differences" panel. Basic merge operations are available in the "Merge" section.

The functionality of the text editor deserves special attention. The appearance lends itself to modification. In addition to syntax highlighting and line numbering, work with scripts is provided, and the expansion of functionality is possible through add-ons. The add-ons relate to the unpacker, view and script editor.

When comparing directories, the results are displayed in a tabulated list. It contains information about the name of the file (directory), its location, comparison result, date, extension and other information. You can customize the display using columns. If necessary, you can activate the recursive mode or switch to the tree view for easy navigation.

WinMerge allows you to perform the same tasks in different ways, including using drag and drop or via the Explorer context menu. You can create projects for quick access to data and settings. WinMerge works in command line mode, and the program can also be used in conjunction with version control systems (TortoiseSVN, Visual Studio, Rational ClearCase, etc.).

Summary... WinMerge is a program primarily with a focus on working with projects. Integration with SVN, a functional editor, filters and extensions - all this perfectly complements the basic capabilities when comparing data.

[+] Extension support
[+] Functional editor
[+] Integration with third-party applications
[-] No three-way comparison

Meld

Meld is a cross-platform program (OS X, Linux, Windows) for synchronizing files and directories. With its help, both two- and three-sided comparison is carried out. First of all, the Meld toolkit will be useful for developers, since it can be integrated with version control systems: Git, Bazaar, Mercurial, Subversion and others.

Despite the support for multiple platforms, the application is far from stable on Windows. Let's say tabs and windows don't always open and close correctly. Perhaps the problem is related to the PyGTK library included in the installer. It was not possible to launch the program immediately and only on behalf of the administrator. Errors occur constantly, in confirmation -.

When comparing files, you can use a text filter or search (regex syntax is supported). There are syntax highlighting (using a library), line numbering, accounting for spaces and other options that need to be activated through the settings, since they are disabled by default. Insertions, changes and conflicts in the document are highlighted, you can quickly navigate through the list of changes and export in diff format. The connection between files is easy to trace using connecting lines and one click to merge the desired sections.

Directory file scanning is very slow. This is because the comparison is based on content, not size and timestamp. The problem is solved by checking the box next to the corresponding option in the settings. The available columns are very limited: size, modification date and resolution. Although you can use the file filter, viewing a long list of files still becomes a chore: you cannot instantly stop scanning, collapse the file tree, or quickly navigate to the desired items.

Developers will be interested in the third mode of the application - Version Control View. Meld supports a command line interface, so there is integration with Git, Bazaar, Mercurial, Subversion, and more.

Summary... Meld has proven itself to be good in Linux, but not in Windows. Unstable work and inconvenient interface, lack of sessions, lack of customization flexibility ... On the other hand, the program's toolkit is not bad, and a high-quality adaptation of Meld for Windows is perhaps only a matter of time.

[+] Three-way comparison
[+] Support for version control systems
[-] Slow and unstable work in Windows
[-] Inconvenient and uninformative interface

Diffuse

Diffuse is a cross-platform product for Windows, OS X, Linux and BSD, with an interface similar to Meld (based on the PyGTK library), but with functional differences. Integration with Bazaar, CVS, Darcs, Git, Mercurial, Monotone, RCS, Subversion and other environments is declared.

Continuing the comparison with Meld: Diffuse is characterized by stability, there are no sudden freezes. Detailed documentation is available, the interface is translated into Russian. However, comparison of directories is not included in the toolkit, the program contains only the functions of comparing files and editing them. In Diffuse, you can find several modes of merging: - two-, three- and multilateral. Thus, there can be as many sources of comparison as you like, the only question is speed and convenience. Regarding the second aspect, we can only say that there are no sessions here - accordingly, working with large projects in Diffuse is questionable.

Differences are highlighted in color, a Comparison Summary is available near the scroll bar, and buttons on the control panel are used to navigate through the list of changes. Line numbering and syntax highlighting with manual switching are enabled by default. Unlike other similar editors, in Diffuse you cannot immediately select an arbitrary section of text; for this, you need to double-click on the content. Otherwise, you can select text and perform other actions only line by line.

Obviously, in Diffuse, there is no linking difference between files, so string merging is done in a less intuitive way. All available commands are collected in the "Merge" section, where you need to contact each time if you do not have commands in the context menu. In SmartSynchronize or other mentioned solutions, many operations are performed in one click.

Work with version control systems is possible through the command line, a list of commands with descriptions is given in.

Summary... This kind of functionality is required when merging multiple text documents. The program is devoid of the shortcomings inherent in the closest analogue of Diffuse - Meld. But, unfortunately, directory comparison and reporting were left out.

[+] Convenient work with strings
[+] Integration with CVS
[+] Multi-window merge
[-] Lack of sessions
[-] Marking changes is not intuitive

Perforce p4 merge

P4Merge is rarely mentioned among other free products (for example, compared to WinMerge). Plus, it's not easy to find this program among the other components of the Perforce suite. Perforce is a commercial cross-platform version control system with a wide range of applications, not least due to plug-ins and integration with various products (IntelliJ IDEA, Autodesk 3D Studio Max, Maya, Adobe Photoshop, Microsoft Office, Eclipse, emacs, etc.) ... However, P4 Merge can work independently of the Perforce server, you just need to download the program from the developer's site for free use.

The main operations are file comparison (Diff) and merge (Merge). The document editor is extremely simple: there is numbering, but there is no syntax highlighting. You cannot edit files in two panels "on the fly", you need to select one of the panels, turn on the editing mode and then save the changes. Differences are marked, navigation buttons are used to navigate between them. The easiest way to navigate changes is using connecting lines. In general, the P4 Merge interface is not user-friendly enough: it does not have a summary of differences, statistics on changes are presented as a summary figure, without detailing, to view the changes, you need to use a manual update.

While listing other features of the program, it is worth mentioning image comparison. In this mode, two useful functions were discovered: highlighting differences and merging two files into one. At the same time, it is not clear why the editor menu contains unclaimed commands, such as changing the encoding, comparison methods, and others that relate to the comparison of text files, but not images.

Summary... Of course, there are many functional limitations in P4 Merge, especially when compared to paid products. The application can be considered purely as an addition to the Perforce server. Perhaps, in search of the right toolkit, you should pay attention to other components available on the developer's site.

[+] Merge diagram in Merge mode
[-] Weak functionality
[-] Inability to edit on the fly
[-] Lack of merge commands

Laziness is the engine of progress, no matter how strange it may sound, some inventions make our life very simple. In my article, I want to tell you how to compare two files in the available ways.
And I decided to write about this after one case when I needed to find out what changes the developers made to the procedure for the database with a new update.

And I was helped in this by two programs that settled with me for a long time:
1. Total Commander
2. Notepad ++

Comparing files in TotalCommander

Let's say we already have two files that we need to compare.
1.Then select them in TotalCommander

2. Go to the FILE menu — -> Compare by content.

3. In the window that opens, we have two areas in each of which you can see the contents of the files.

As a result, lines with changes are highlighted in gray, specific differences in red.

To move to the next block of differences or return to the previous one, TotalCommander has buttons "Next difference" and "Previous difference" in the menu. Here you can activate the editing mode by pressing the "Edit" button, after that you can change the font, copy lines from window to window, and in case of an erroneous action there is a saving button "Rollback".

After editing, the program will ask what to do with the files: save or not save.

Comparing files in Notepad ++

Notepad ++ is in my opinion the best notebook everyone should have. It has a lot of functionality, expandable with plugins.

So how can Notepad ++ help us to compare files? The answer is simple: you need to download the required plugin.

Open the item "Plugins" -> "Plugin Manager" -> "Show Plugin Manager".

A large list of various plugins will be poured out in the opened manager. We choose " Compare " and install.

  1. open two files in Notepad ++.
  2. We make it so that both files are open in tabs next to each other.
  3. On the menu bar, go to Plugins -> Compare -> Compare, or use the hotkeys - Alt + D and launch the plugin.

In the opened window as in TotalComander, we have two areas in each of which you can see the contents of the files.

Red minuses are something that has left,

The yellow exclamation marks are what has changed.

Exit the Compare mode via the Plugins menu -> Compare -> Clear Results, or Ctrl + Alt + D.

It so happens that you have two almost identical texts, and you need to clearly see how exactly they differ. A common example: you “removed” an interview from the recorder and sent it to a demanding interlocutor for proofreading. And he, instead of highlighting his edits with color, simply cut out some phrases, added new ones, changed the places of paragraphs.

As a result, you seem to be reading your own interview, but you don't recognize it in makeup. It is difficult to compare manually two large texts - can you make this task easier? site will tell you how.

Such tasks often arise before programmers, therefore programs for comparing files are able to highlight syntax when comparing program codes of different programming languages. We also need such programs to allow us to compare texts in the usual .txt format and, preferably, in the "Word" format.

For comparison, we took several paragraphs of our article and replaced some words, swapped phrases. Now we will compare.

Microsoft Word

In a Microsoft Office program starting from the 2007 version, you can compare two files without leaving the Word. Go to the menu item Review - Compare - Compare ... (compare two versions of the document). Specify two files, press the "More" button and mark the parameters by which you want to compare the text, and also choose where to view the changes: in the first file, in the second or in a new one.

The program highlights deleted text with red strikethrough text, inserted text with red underlined text, and moved paragraphs with green text. In a separate panel on the left (it is not in the screenshot below), you can track changes for each word, as well as see a summary: in our case, 57 corrections, of which 26 are insertions, 29 deletions, 2 movements.

WinMerge is a free cross-platform file comparison utility that can be used on a rich zoo of operating systems starting with Windows 98. The latest version, WinMerge 2.14.0, exists both as an installer (6.14 MB) and portable assembly. The program "out of the box" can only compare ordinary text files, and if we want to work also with office documents (texts in .doc, .docx, .odt formats, tables in .xls, .xlsx, .sxc formats, PDF files and other office files in exotic formats), you need to download the Xdocdiff plugin. The plugin is connected as follows:

1) Unpack the archive with the plugin

2) Copy the files xdoc2txt.exe and zlib.dll to the folder with the WinMerge program installed

3) Copy the MergePlugins folder together with the amb_xdocdiffPlugin.dll file in its entirety to the folder with the WinMerge program installed

4) Launch WinMerge, go to the Add-ons menu - List, tick the "Enable add-ons"

5) Go to the Add-ons menu - check the box "Unpack automatically"

That's it, now you can open two of our files: if you want - the usual "teekstashny", if you want - "Word".

The program will warn you that you can also specify zipped files, but for this you have to download the archiver plugin. However, we are not afraid of his absence, we refuse future similar notifications and get a window with our two texts. On the left side of the window there are two long columns: these are the thumbnails of our texts. Paragraphs in which changes were found are highlighted in yellow. Since each of the three paragraphs of our original text contained such changes, both columns are highlighted in yellow. Specific modified words are highlighted in light yellow.

But the program has many settings, so it's easy to highlight words in some other color.

There are many programs for comparing files, including text files, their main drawback is the price. Compare it! costs $ 29 per license, Beyond Compare - $ 30, Compare Suite - $ 70, DiffDoc Professional - as much as $ 399.95. Let's look at the example of this last, most expensive program, how much better it is than the free WinMerge.

Download the program (7 MB), run it. The result is very similar to the one given by Microsoft Office 2007, only the layout of the columns is different. Red strikethrough - text that was changed, red underlined - text to which the original was changed (red strikethrough); blue strikethrough - cut text, green - moved (or added "from scratch") text.

It turns out that there is practically no difference. If the user honestly bought an expensive Microsoft office suite, then there is no point in spending another $ 400 on the official purchase and registration of this program. There is no need to use even the "trial" version if the same functionality is provided by the standard "Word", especially since the unregistered version of DiffDoc Professional reminds you to purchase every 15 minutes.

Finally, let's check one of the many online text collation services: DiffNow

The service seems to support loading doc files, "swallowed" them, wrote Files compared successfully, but instead of a normal result it produced a binary set of zeros and ones, in which, however, it highlighted the differences. Therefore, it is better to copy and paste the text manually. The site highlights the changes as follows: brown - changed text, blue - deleted, burgundy - added, purple - changed words in changed sentences. The service supports various settings (including you can replace colors), but we could not get rid of one drawback with any settings: the text in a programmer's way is stretched in length, we have to use horizontal scrolling.

© 2021 hecc.ru - Computer technology news