Preface In the process of writing code, we will inevitably make some modifications to the code. But it often happens that when you are making changes, you don’t know what the difference is between the modified file and the source file. Here, we need a text comparison tool to perform text comparison. Experienced programmers know that there is a very useful text comparison tool under Windows - BeyondCompare. But it is paid software, and many regular companies do not allow the use of cracked software. Moreover, it is only available under Windows and there is no Linux version. The text comparison method introduced in this article does not require any software, only a Linux command. Once you learn this command, I will no longer be worried about you not knowing how to do text comparison. This Linux command is the diff command. diff is a very important tool program in Unix system. It is used to compare the differences between two text files and is one of the cornerstones of code version management. First, let's look at its basic command format. diff [OPTION]... FILES It's very simple. But it has so many options that you will question your life. Let’s not worry about that for now and learn the most commonly used ones first. After all, time should be spent wisely. -b - Ignore differences in blank characters within a line (e.g. "Hello World!" is considered the same as "Hello World!!") -B — ignore blank lines -i - Ignore case differences -r —— If diff is followed by a directory, it will recursively compare the files in the subdirectories. Let's take a closer look at how to compare text. The diff command has three output formats: (1) Normal format (normal diff) (2) Context diff (3) Unified diff We introduce these three output formats in detail through examples. For example, we now have a file ac, its content is as follows: Now we make a copy, name it bc, and change the lowercase "hello" in line 3 to uppercase "HELLO", as follows: (1) Normal format In normal format, we don't need to add any options, just compare as follows: The results after execution are as follows: Let's explain the meaning of the above picture line by line. Row: 3c3 The first 3 indicates that the third line of file ac has changed, and the following 3 indicates that ac has changed to become the third line of bc. The c in the middle is the specific change. c stands for change, and other types include d for deletion and a for addition. Line 2: < hello world! It means to remove the content of line 3 in the ac file, where the less than sign indicates removal. Third line: ------ Divider Line 4: > HELLO world! It means adding the content of line 3 to the bc file, where the greater than sign indicates increase. (2) Context format Because there is relatively little prompt information in the normal format, we cannot quickly locate the modified area and often need to open the file to know the modification details. So, in order to give more information, the context format was introduced. Its usage command is as follows: diff -c ac bc Among them, c stands for context, which means context. The specific meaning of the output results in the above figure are as follows: The first and second lines indicate the files before and after modification and the update time. The following *** 1,4 **** indicates the contents of the ac file starting from line 1 to line 4. The exclamation mark (!) before hello world indicates that the line has been changed. If the line is deleted, it is a minus sign (-), and if the line is added, it is a plus sign (+). The following lines have similar meanings. (3) Merge format This format is a combination of the normal format and the context format, and is also the format used by git diff. The command using this format is: diff -u ac bc The detailed meaning of the output results in the above figure are as follows: The first and second lines indicate the files before and after modification and the update time. The -hello world! at the end refers to the content in the original file ac, and +HELLO world! refers to the content in bc. In addition to the above three formats, there is another more intuitive way - the side-by-side format. The command format for this display format is as follows: This format is displayed in a parallel format, which is also very intuitive and clear. In line 3, there is a “|” symbol, indicating that this line has been changed. In addition, if the leading character is “<”, it means that the following file has one less line of content than the previous file; if it is ">", it means that the following file has one more line of content than the previous file. Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM. You may also be interested in:
|
<<: How to upgrade MySQL 5.6 to 5.7 under Windows
>>: Vue2.x - Example of using anti-shake and throttling
background We can use react-color to implement th...
1. Window -> preferences to open the eclipse p...
I was playing with CentOS in a VMware virtual mac...
Linux installation JDK1.8 steps 1. Check whether ...
Table of contents Preface props context state Sum...
This article shares the specific method of instal...
General mobile phone style: @media all and (orien...
1. flex-grow, flex-shrink, flex-basis properties ...
Table of contents 1. What is Promise? 2. Why is t...
This article uses examples to explain the princip...
Document Scope This article covers mode switching...
Table of contents Overview Form validation withou...
The TextBox with the ReadOnly attribute will be di...
mktemp Create temporary files or directories in a...
This article example shares the specific code of ...