Linux text processing 3
Diff
The diff command is used to display differences between files. Diff supports multiple output formats and can process many files at a time.
Diff is generally used to detect changes between source code of multiple versions, and then convert the old version into a new version. diff can also recursively check the source code Directory, which is called the source code tree. A common application of the diff command is to create a diff file or patch, and then use the patch program to convert the file from one version to another.
Diff default output Parsing
In the default output, each group of changes is a change command. The command format is: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + examples/examples + hvsS/serOxLz + examples/examples + CjxwPtXiwO + 1 xNDQzqq/examples + ttTUrcq8zsS8/examples + examples/TwvcD4KPHA + examples + release/rj2zsS8/release + uPbOxLz + release + 0NC4/release + s/release + 0NC9q7vhs/bP1tTatdq2/rj2zsS8/release + Cgo8cD6z /examples/a7udPQyc/examples/serOxLz + t9a/examples + us3Ev7HqzsS8/r3hus/Vucq + examples + yc/examples + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20150409/20150409100405111.jpg" alt = "\">
The content of the first file is identified by *, and the content of the second file is identified.
Blank: displays the rows in the context. It does not indicate the difference between two files. -: Delete rows. This line will appear in the first file instead of the Second file. +: Add rows. This line will appear in the Second file instead of the first file .! : Change the row. Two versions of a text line are displayed. Each version is displayed in the respective part of the reorganization. Unified mode: Use the-u option to specify the uniform mode (uniform)
Blank: Both files contain this line. -: Delete this row from the first file. +: Add this row to the first file. Use diff and patch to convert a file from a general version to a new version.
Diff-Naur old_file new_file> diff_file (u: uniied, a: text, N: num, r: recursive) patch <diff_file
It can be seen that after the patch is used to convert the original file, the diff command is used to compare the old and target files without generating diff information.
Tr
The tr command is a character-based search and replacement operation. Tr receives data from the standard input and outputs the processed data to the standard output.
Tr usage: tr [Option] [combination of original character sets] [combination of target character sets]
The basic options are as follows:
-D: Delete characters in the original character set-c: replace the original character set with the characters in the target Character Set-s: compress the data in the standard input according to the characters in the original set character set can have the following three representation: enumerated list: ABCDEFGHIJKLMNOPQRSTUVWXYZ character field: A-Z. Note that this method sometimes faces the same problem as other commands and is attributed to the sorting rules of the language family. Therefore, you should exercise caution when using this method. POSIX character class: [: upper:] One of the usage of tr is to delete ^ M in the dos file. The command is tr-d "\ r'filename