0520 Sixth session

Source: Internet
Author: User

Description and usage of special permissions go directly to the end of the note in the previous lesson


















Text Processing Tools



1.cut: Cut the data into segments with a separator and extract one of the sections

-d:d followed by the delimiter directly

-f:f back with the number of segments you want to extract, multiple segments, separated



2.more/less: Page Turn display

COMMAND |more/less-d: D is a few simple help tips



3.head: Display the first few lines

-#: Show Front # line


4.tail: Show the end of a few lines

-#: Show End # line

-F: Monitoring end Add, usually with & background use

-N +k: Starting from line K



5.paste: Merge Command

-D: Delimiter, two files merged together to differentiate between two data separators

-S: one row of data


6.uniq: Count of commands

-C: Number of occurrences of statistics

-U: Show rows with no duplicates

-D: Show Duplicate rows


7.diff: Compare the differences between two files

-U: The structure of the comparison is output in a special format and can be used as a patch when redirected to a file


8.patch:

-I: Change the format of File1 to diff output to File2

-R: Converts the file2 to a diff output format into file1

-B: Back up and save a copy before doing IR operation










Regular expressions and Linux text Processing Three Musketeers



Text Processing Three musketeers: grep: Filtering text

Sed: Editing text


awk: Text Report Generator



grep: Filter Text Tool

grep: Supports regular expressions


Egrep: Supports extended expressions


Fgrep: Regular expressions are not supported

Between three can be converted by option: Grep-e =egrep

Grep-f =fgrep




grep "Options" pattern file


-I: Case sensitive

-O: No rows are displayed, only matching data is displayed

-V: Shows what is outside the row where the matched data is located

-Q: Silent mode, regardless of whether the match is not displayed

-E: Supports extended regular expressions

-A #:after, the next # line of the matched line is also displayed

-B #:before, up # line

-C #: Context, Upper and lower # lines



Regular expressions: Just some symbols for the text, and the previous * a bit similar, but the meaning of each symbol is completely different, pay attention not to confuse


Character matching:. : Any single character

[]: Specify any single character of the range

[^]: Create any single character outside the range

[: Space:] [:d Igit:] [: Alnum:] [: Alpha:] [: Lower:] [: Upper:] [:p UNCT:]

Meaning with wildcard characters


Word number match: *: The character of the front appears as many times as 0,1,2, ....

\?: The preceding character appears 0 or 1 times, i.e. the data in front is optional

\+: The preceding character appears more than 1 times

\{m\}: The characters in front appear m times, one less time, no more

\{m,n\}: The character at the front appears at most n times at least m times

\{0,n\}: Up to n occurrences of characters in front

\{m,\}: The character at the front appears at least m times

Position anchoring: ^: Beginning of line, on the left of pattern

$: Line bit right

^$: Blank lines, not even spaces

^[:space:]*$: Blank line, with spaces

\<: The head of the word, placed on the left side of the word

\>: Ending, right

\<\>: Word anchoring


Grouping and referencing: \ (\): Fu Guacheng multiple words into a whole


\1: Refers to the front parenthesis, from the leftmost first left parenthesis, to its matching parentheses, the contents of the parentheses inside

\2: two X

\3: three X

\4: Four X


Note: This type of reference is called a back reference


Egrep: Extended Regular expression content is basically the same as regular expressions, except that when the words match, the \ can not be added

Different


Or: |:| all content on the left or | right all content


Note: | When used in certain environments, add \ to escape


C|CD: Refers to C or CD instead of CD or CD, want to express the meaning of the latter need to use the grouping, that is, parentheses

\ (c|c\) d to indicate


Fgrep: grep that does not support regular expressions is not useless, because many of the documents we want to retrieve in the future are large documents with very large data, so in the case of non-regular expressions,

The efficiency of using fgrep will be higher




Regular expression is an important content, but also a need to move the brain content, should do more practice



This article from "Blog Work First Edition" blog, declined reprint!

0520 Sixth session

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.