Bird Book Shell learning Note (ii) shell-related expressions

Source: Internet
Author: User

Wildcard characters differ from regular expressions The wildcard is the syntax that bash native supports,A regular expression is a representation of a string, and regular expressions require supported tool support to
Language settings: Export lang=cgrep alias settings: grep--color=auto
Some of the advanced parameters of grep
grep [-A] [-b] ' search string ' filename///output before the K-line and after the M-line-A: The following can be added number, indicating the list of rows and after the N line-B: List the previous lines
Search for keywords If you use regular expressions in the middle, then the regular expression section needs to add []eg:grep ' [a-z]oooo ' filename
Match the beginning of ' ^string ' but ' [^s]string ' means exclude s This letter matches line end ' string$ ' eg: Exclude comment lines, and empty lines grep-v ' ^$ '/etc/profile | Grep-v-n ' ^[[:blank:]]*# '


SED usage
sed [-NEFR] [action] sed can be manipulated directly on the fileOptions and Parameters:-N: Use Quiet (silent) mode. In the usage of general sed, all data from STDIN is generally listed on the screen. However, if you add the-n parameter, only the line (or action) that is specially processed by SED is listed. -E: Directly in the command columnmode.The action editor of Sed;-F: Writes the action of SED directly into a file, and the-f filename can run the SED action in filename; the-r:sed action supports the syntax of the extended formal notation. (The default is the basic formal notation of French)-I: Directly modifies the contents of the read file instead of being output by the screen. Action Description: [N1[,n2]]functionn1, N2: Not necessarily exist, generally represents "select the number of lines of action", for example, if my action is required between 10 to 20 rows, then the "10,20[action behavior" function bottom The following: A: New, a can be followed by a string, and these strings will appear in a new line (the current next line) ~c: Replace, C can be followed by strings, these strings can replace the line between N1,N2! D: Delete, because it is deleted, so d usually do not take any knock; I: Insert, I can be followed by a string, and these strings will appear on a new line (the current line); P: Print, that is, print out a selected data. Normally p will run with parameter sed-n ~s: Replace, can be directly replaced by work! Usually this s action can be paired with formal notation! For example 1,20s/old/new/g is! 

EG:NL Regular.txt | Sed ' 2,5d '//delete second to fifth line, the action behind SED must be "extended"
NL Regular | Sed ' 2a add hello ' after the second line adds data
NL Regular | Sed ' 2,5c change 2 to 5 line content ' replaces the contents of 2-5 lines
NL Regular | Sed-n ' 2,5p ' selected lines print out

Find and replace sed ' s/string to be replaced/new string/g '
Cat. BASHRC | Sed ' s/#.*$//g ' | Sed ' s/^$//g ' |grep-n ' exp '//Delete comment lines and blank lines

Sed-i ' s/\.$/\!/g ' regular//modify file directly

Awk's handy data processing tool
Suitable for small data processing
awk ' condition type 1{action 1} condition type 2{action 2} ... ' filename


wildcard characters

Special Regular
Regular
expansion of the regular

Bird Book Shell learning Note (ii) shell-related expressions

Related Article

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.