Regular Expressions and file formatting in laruence Linux private house-Basic Learning

Source: Internet
Author: User

Regular Expression and file formatting Regular Expression in "laruence's Linux private house dish-basic learning": A string processing method, which processes strings in the unit of action, regular Expressions help users easily find, delete, and replace a specific string. The regular expression www.2cto.com is basically a "notation". As long as the tool program supports this notation, the tool program can be used as a regular expression string for processing. Influence of the basic Regular Expression Language on regular expressions; When LANG = C: 0 1 2 3 4... A B C D... Z a B c d... ZLANG = zh_CN: 0 1 2 3 4... A A B B c C d D... When using a regular expression, z Z should pay special attention to the environmental language at that time. Otherwise, it will be found that the selection results are different from those of others. In order to avoid the English and numerical selection problems caused by encoding, special symbols: www.2cto.com [: alnum:] English case characters and numbers [: alpha:] English case characters [: upper:] English case characters [: lower:] English case characters [: digit:] number grep [-A] [-B] [-color = auto] 'searched string 'filename' parameter:-A: numbers can be added to the end, meaning after, in addition to listing this row, the next n rows are also listed as-B: numbers can be added to the end, which is the meaning of befor. Besides listing this row, the preceding n rows also indicate that the set value grep of "export LANG = C" has been set as "grep -- color = auto" using alias to search for specific strings using brackets []. internal and external It is different. In [], it indicates "reverse selection". In addition to [], it indicates locating any character at the beginning of the line: ^ $ (only the beginning and end of the line. (decimal point): represents a certain number of characters and repeated characters * (asterisks): represents repeating the first character, 0 to infinite meaning ". * "indicates that the meaning of zero or any number of characters is limited to the range of consecutive RE characters {}: the special characters of the Escape Character \ regular expression must be used. The wildcard character entered in the command line is not the same as that of the General Command. sed [-nefr] Action parameter:-n: Uses quiet mode, in general sed usage, all data from STDIN is usually listed on the screen. However, if the parameter-n is added, only one line (or operation) that has been specially processed by sed) -e: directly edit the sed action in command line mode-f: Write the sed action in a file, -f filename: The sed action in filename-r: sed Action supports extended regular expression syntax (default: Basic regular expression syntax)-I: direct modification The content of the file to be read, instead of the output action on the screen. Description: [n1, [n2] functionn1, n2: Generally, the number of rows selected for the action function has the following parameters: a: New c: replace d: delete I: insert p: Print s: replace,'s/the character to be replaced/the action next to the new string/g'sed, always enclose $ with "two single quotes" to indicate that when several rows are added to the last row, awk must be added to the middle of each row using a backslash: A good data processing tool, sed, is often used to process a whole row. awk tends to divide a row into several "fields" for processing. Therefore, awk is suitable for processing small data processing. awk 'condition type 1 [Action 1] Condition Type 2 [Action 2]… 'Filenameawk mainly processes data in fields in each row. The default field delimiter is the Space key or the [Tab] key. Each field in each row has a variable name, $1, $2. $0 indicates a whole row of data. The whole awk processing process is: Read the first row, and enter the data in the first row in the variable name according to the condition type restrictions, determine whether or not to perform subsequent operations to complete all the actions and condition types. If there are still subsequent "rows" of data, repeat the above 1 ~ Step 3: awk processes the data once until all data is read, and the unit of field processing is the smallest. awk has the built-in variable: NF: Total number of fields owned by each row NR: currently, awk processes the data FS of the "nth line": the current delimiter. The default Delimiter is the Space key awk logical operator ><>==! = All awk actions, that is, actions in {}. If multiple command aids are required, use semicolons, you can also directly use the [enter] key to separate the logic operations of each command. If it is "equal to", always use = to format the output, in the printf format setting, you must add \ n to make the branch variable available for direct use. You do not need to add the $ file to compare the differences between configuration files and source files in different versions of the same software. Www.2cto.com diff: used for comparing ASCII plain text files. It is usually used in the old and new versions of the same file (or software). Difference diff [-bBi] from-file to-file parameter:-B: ignore the difference of multiple white spaces in a row-B: Ignore the difference of blank rows-I: Ignore the case sensitivity cmp [-s] file1 file2 mainly uses the "Byte" unit to compare parameters: -s: columns the bytes of all different points, because cmp only outputs the patch of the first detected difference by default to make the difference file into a patch file: dif-Naur old file new File> *. patch Update: patch-pN <patch_file Restoration: patch-R-pN <patch_file parameter:-p: the number of N after which the directory is canceled-R: Indicates restoration, restore the new file to the old version. Print the preparation: pr.

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.