The learning experience of Linux from the Apprentice Brother (11)--Formal expression and file format processing

Source: Internet
Author: User

1. Formal notation is the method of processing strings, the processing of strings in the unit of behavior, through the assistance of some special symbols, can let the user easily to search, delete, replace a particular string of handlers. As a simple example, we know that the mailboxes are in a specific format and can be filtered using this format to delete non-conforming strings. As long as every time there is a letter, the title of the letter and the content of the special string comparison, found that there is bad mail to be removed.

2. The most commonly used instruction in formal notation is grep, which means that a match, such as grep ' eth0 ', is to find the line containing the eth0. Grep is also in the behavior of the data matching, in order to highlight the content of the search, you can add color, the practice is to add "alias grep = ' grep--color=auto '" in ~./BASHRC, and then use the source to make the BASHRC file take effect, So every time you search with grep, the information is colored.

3. Search for a specific string: Grep-n ' the ' 1.txt--search for the string

Reverse Search: Grep-vn ' the ' 1.txt (v is inverse)

4. In conjunction with the previous matching usage, here is a summary of the following:

^word: string with search word at the beginning of the line

word$: string with search word at end of line

\: Skipping characters, deleting special meanings of special symbols

*: Repeat 0 to infinitely multiple of the previous character

N1-N2: Lists the range of characters you want to match

^list: Character not in list

5. Okay, here's the comparison between the files, mainly using diff and cmp two instructions.

diff: Compare the differences between the two files and compare them in behavioral units, generally used in the comparison of ASCII plain text files, usually for the old and new versions of the Unified Archive. For example, diff Passwd.old Passwd.new, which shows the result is 4d3, means that the fourth line on the left is deleted (d is delete), and the Datum is the third row on the right. Don't use diff to compare files that are completely irrelevant, because there's nothing.

CMP: For each byte of comparison, usage is the same as diff, that is, CMP passwd.old passwd.new

6. Patch: Is the patch, used to upgrade the file, compare the differences between the old and new versions, and make the diff file as a patch, and then update the old file by the patch file. Usage is Diff-naur passwd.old passwd.new > Passwd.patch

The learning experience of Linux from the Apprentice Brother (11)--Formal expression and file format processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.