Linux Regular expressions and file format processing instructions

Source: Internet
Author: User
Tags clear screen compare binary files diff print format printable characters dmesg

1. Special symbols:

1) [: Alnum:]: Letters and numbers

2) [: Alpha:]: Letter

3) [: Blank:]: Space and TAB key

4) [: Cntrl:]: Control key Cr,lf,tab,del, etc.

5) [:d Igit:]: Digital

6) [: Graph:]: Other keys except whitespace (Space and tab)

7) [: Lower:]: Lowercase Letter

8) [:p rint:]: Printable characters

9) [:p UNCT:]: Punctuation

TEN) [: Upper:]: Uppercase

one) [: space:]: whitespace characters, such as spaces, tab,ctr, etc.

[: xdigit:]:16 binary digits

2.grep [-ab] [--color=auto] ' search string ' filename: Parameter

1)-a:after, followed by a direct number, in addition to listing the row, also lists the following n rows

2)-b:before, followed by a direct number, in addition to listing the row, also lists the following n rows

Other parameters can be consulted: http://7613577.blog.51cto.com/7603577/1595762

3.DMESG [-cn][-s < buffer size]: Displays boot information, saved in/var/log directory, parameters:

1)-C: Clears the contents of the ring buffer after displaying the information

2)-s< buffer size: Pre-set to 81896, just equal to the size of ring buffer

3)-N: Sets the level of logging information

Description: This instruction is mainly used to display kernel ring buffer contents, and the kernel stores various messages here. At system boot time, the kernel fills in this buffer with information about hardware and module initialization. A message in the kernel buffer is often useful for diagnosing system problems. When you run DMESG, it displays a lot of information. It is common to use the pipe to view the output of DMESG through less or grep, which makes it easier to find unknown origin information.

4. In the regular expression, "." Have and have only one arbitrary character; "*": indicates that the previous character is repeated 0 or more times.

5. Summary of regular Expressions:

1) ^word: characters to be searched at the beginning of the line

2) word$: characters to be searched at the end of the line

3).: An arbitrary character

4) \: Escape character

5) *: Repeat the previous character 0 or more times

6) [list]: matches any one of the characters in brackets

7) [N1-N2]: match one of the consecutive characters from N1 to N2

8) [^list]: matches any character except List

9) \{n,m\}: Repeats the previous character N to M times

6.sed [-NEFR] [action]: Pipeline command, you can replace the data, delete new, retrieve specific rows, etc., parameters,

1)-N: Use Quiet mode, in general SED usage, all data from stdin will be listed on the screen but if you add the-n parameter, only the line which is specially processed by SED will be listed

2)-E: The Action of SED is edited directly in the instruction-column mode, that is, multiple commands are continuously operated.

3)-F: Directly write the SED action in a file, and-f filename to perform the SED action in filename

4) The-r:sed action supports the syntax of the extended regular notation

5)-I: Directly modify the contents of the read file instead of the screen output

Action Description: ' [n1][,n2] function '

N1,N2: Not likely to exist, generally means "Select the number of rows to perform the action

The function has the following:

1) A: New, a can be followed by a string, and these strings will appear on the next line

2) C: Replace, C can be followed by strings, these strings can replace the line between N1,N2

3) d: Delete,

4) I: Insert, I can be followed by strings, and these strings will appear on a new line (the current line)

5) P: print, i.e. print a selected data, usually p will work with parameter sed–n

6) S: Replace, can be directly replaced by the work, usually this s can be paired with the regular notation.

7.egrep: An extended regular expression, equivalent to the enhanced version of grep, extending the special symbols supported by regular expressions:

1) +: Repeats one or more previous characters

2)? : 0 or one of the preceding characters

3) |: Find several strings in a way or

4) (): Find the group string

5) () +: repeats the characters in parentheses one or more times

8.printf ' Print format ' actual content: Non-pipeline instructions, print format:

1) \a: Warning Sound output

2) \b: Backspace key

3) \f: Clear Screen

4) \ n: output a new line

5) \ r: i.e. enter key

6) \ t: Horizontal Tab key

7) \v: Vertical Tab key

8) \xnn nn is a two-digit number that can be converted to a number called a character

Common parameter formats

1)%ns:n, number, s string, that is, how many strings

2)%ni:i,integer, which is the number of integer words

3)%n.nf:f,float, that is, n-bit integer digits, and n-bit decimal digits

9.awk ' condition type 1{action 1} condition type 2{action 2} ... ' FileName: Data processing tool for small data processing, which can process subsequent files, or read standard Out,awk from the previous instruction to process data in each line of the segment, The default field delimiter is a space or TAB key. That is, by $n (n starting from 1), the first few fields are represented. Awk in the Behavior Processing unit, the field is a minimum processing unit, awk built variables,

1) NF: Total number of fields per row ($)

2) NR: The first few rows of data that awk is currently working on

3) FS: The current delimiter, the default is the space key

awk logical operation character: >,<,>=,<=,==,!=.

awk's instruction interval: all awk actions, that is, actions within {}, if more than one instruction is required, can be separated by the ";" interval, or directly by the ENTER key.

When formatting the output, be sure to add \ n in the format of printf for analysis

Variables in awk can be used directly without adding the $ symbol

AWK also supports if condition judgment.

10.diff [-bbi] from–file to-file: Used to compare the differences between the two files, and are compared in behavioral units. Parameters:

1) From-file: A file name, as the original comparison file name

2) To-file: A file name, as the purpose of comparing the file name

Here From–file or to–file can be used-instead, that-represents the meaning of the standard input.

3)-B: Ignores a single line, with only a number of whitespace differences

4)-B: Ignore differences in blank lines

5)-I: Ignore case differences

You can generate a diff file by Diff-naur file.old File.new>file.patch: In the file, the beginning of the "-" symbol for the old file deleted content, + represents the new file added content.

11.cmp [-S] file1 file2: Compare two file differences by byte units, parameters:

1)-S: Lists all the different points at the byte, because the default CMP only outputs the first discovery difference.

This command is used to compare binary files.

12.PATCH–PN <patch_file, update the file; Patch-r–pn <patch_file, revert to the old file: parameters,

1)-P: Can be removed after several levels of directory

2)-r: Represents the restore, restores the new file to the original old file

where Patch_file is the diff generated differential file

13.PR: Print The file instructions, there will be page numbers, headings, etc.


This article is from "Tiger Brother's Blog" blog, please be sure to keep this source http://7613577.blog.51cto.com/7603577/1596571

Linux Regular expressions and file format processing instructions

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.