Linux--Shell programming

Source: Internet
Author: User

Linux--Shell programming one, regular expression 1, regular expression PK wildcard

    

    

2.Basic Regular Expressions1),*The previous character matches 0 or more times

~ grep "A *" Test_rule.txt # matches all content, including blank lines

~ grep "aa*" Test_rule.txt # matches a string that contains at least two consecutive a

~ grep "aaa*" Test_rule.txt # matches a string with a minimum of two consecutive a

~ grep "aaaa*" Test_rule.txt # matches a string with a minimum of four consecutive a

2),.Match any character except line break

~ grep "s.. D "Test_rule.txt #" s.. D "matches a word that must have two characters between the two letters S and D

~ grep "S.*d" Test_rule.txt # match has any character between S and D letters

~ grep ". *" Test_rule.txt # matches all content

3),^Match beginning

~ grep "^m" Test_rule.txt # matches lines beginning with uppercase "M"

4),$Match end of Line

~ grep "n$" Test_rule.txt # matches lines ending in lowercase "n"

~ grep-n "^$" Test_rule.txt # matches blank lines

5),[]Matches any one of the characters set in brackets, matching only one character

~ grep "S[ao]id" Test_rule.txt # matches S and I in the letter, but not a, but

~ grep "[0-9]" Test_rule.txt # matches any number

~ grep "[A-z]" Test_rule.txt # matches a line that starts with a lowercase letter

6),[^]Match any character except the character in brackets

~ grep "^[^a-z]" Test_rule.txt # matches lines that start with no lowercase letters

     ~ grep "^[^a-za-z]" Test_rule.txt # matches lines that don't start with letters

7),\Escape character

~ grep "\.$" Test_rule.txt # Match use ". "End of Line

8),\{n\}Indicates that the preceding character appears exactly n times

~ grep "A\{3\}" Test_rule.txt # matches a character string that appears three consecutive times

~ grep "[0-9]\{3\}" Test_rule.txt # matches a string containing three consecutive digits

9),\{n,\} indicates that the preceding character appears not less than n times

~ grep "^[0-9]\{3,\}[a-z]" Test_rule.txt # matches a line that starts with a minimum of three consecutive digits

10), \{n,m\} matches the characters preceding it at least n times, with a maximum of M times

~ grep "Sa\{1,3\}i" Test_rule.txt # match between letter S and letter I have at least one a, up to three A

Second, character interception command 1, cut 1), field Processing command 2), cut [options] file name

[Options]

-F Line Number: Extract the first few columns

-D delimiter: Split columns by specified delimiter

3), Example:

      

      

      

   4) Example limitations (cannot match spaces)

      

2, PRINTFF 1), usage

 print ' Output type output format ' output content

        

        

2), Practice

      

      

      

      

3) and the relationship to awk (printf uses nothing more than a dick, mostly with awk)

Print:print will automatically add a newline character after each input (Linux defaults to no Print command).

printf: is the standard format Output command, and does not manually add line breaks, if you need to wrap, you need to manually add line break

Example

        

        

3, awk 1), use:awk ' condition 1 {action 1} condition 2 {action 2} ... '

Condition: general use of relationship expressions as criteria

x>=10 greater than or equal to

X > 10 determine if the variable x is greater than 10

x<=10 less than or equal to

Action

Formatted output

Process Control Statements

2), BEGIN, END, FS built-in variables, relational operators

      

      

      

      

      

4. Sed

1), Introduction:

SED is a lightweight flow editor that is almost included on all UNIX platforms, including Linux.

SED is primarily used to select, replace, delete, and add commands to the data.

2), Usage:

Sed "Options" "Actions" file name

"Options"

N

E

I

"Actions"

A \:

C \:

i \:

Three, character processing command 1, sort 2, WC four, condition judgment five, flow control 1, if 2, Case 3, for 4, while and until

Linux--Shell programming

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.