The pipeline, redirection and regular expression of Linux learning notes

Source: Internet
Author: User

Pipeline: The output of the previous command, as input to the latter command

Command 1 | command 2 | command 3| command 4  

#tee that is displayed on the monitor, and the file is saved in the file

Example #echo "Hello, word" | Tee/tmp/hello.out

Example #wc-l/etc/passwd | Cut-d '-f1


I/O redirection

> output redirection, overwrite output

> > Append Output

#set-C Disables overwrite redirection for existing files, forcing overwrite of output, using >|

#set +c Turn off the above features  

2>: Redirect Error output

2 >>: Append redirect Error output

Example: #ls/varr>/tmp/var.out 2>/tmp/var.out, correct output and error output overwrite/tmp/var.out file  

&>: Redirect standard output or error output to the same file  

< input redirection,

Example: # tr ' A-Z ' A-Z ' </tmp

<< Append Input

Example 1: #cat >>/tmp/file.txt <<eof: Save keyboard input to File.txt

Example 2: #cat <<eof

d| D Show Delect

U|u Show UID

EOF: Display the content information in the script


Regular Expressions: Regular expression, REGEXP

Basic REGEXP: Basics

Extended REGEXP: Extended

Basic Regular Expressions:

Metacharacters

. Any single character

Example #grep ' r.. T '/etc/passwd

* The number of previous character matches

. * matches any character of any length

\? Match its preceding character 1 or 0 times

\{m,n\} indicates that the preceding character appears at least m times and at most n times

Position Lock:

^: Anchor the beginning of the line, any content after this character must appear at the beginning of the line

Example: grep ' ^r. T '/etc/passwd

$:: Anchor line end, any content in front of this character must appear at the end of the row

Example: grep ' b$ '/etc/passwd

^$: Blank Line

Example: grep ' [[:d igit:]] '/etc/inittab

\< or \b: Indicates that any subsequent character must appear as a word header

\> or \b: Indicates that any character preceding it must appear as the tail of the word

Group

\ (\) \ (ab\) means ab a whole

\1: Indicates the contents of the first opening parenthesis and the corresponding closing parenthesis

example : #grep '. *\ (L. e\). * \1 '/tmp/

Example # grep ' \ ([0-9]\). *\1$ '/etc/inittab

Example: #grep ' ^1\ ([0-9]\): \1.*\1$ '/etc/inittab

To extend the regular expression:

Character matching

. any single character

[] matches any single character within the specified range

[^] matches any single character outside the specified range

Number of Matches

* the number of previous character matches

? match its preceding character 1 or 0 times

+ match the characters in front of it at least once

[M,n] indicates that the preceding character appears at least m times and at most n times

Anchor Point character

^ Anchor The beginning of the line, any content after this character must appear at the beginning of the line

$ Anchor Line end, any content in front of this character must appear at the end of the row

\< indicates that any subsequent character must appear as a word header

\> indicates that any character preceding it must appear as the tail of the word

Group

()

\1 \2 \3

Or

| : B|a left character or right character

Example: #grep-e--color ' ^[[:space:]]+ '/boot/grub/grub.conf


This article is from the "Wish_" blog, be sure to keep this source http://itwish.blog.51cto.com/11439802/1965086

The pipeline, redirection and regular expression of Linux learning notes

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.