^ First line Locator
^ Love matches all rows starting with love
$ Line tail Locator
Love $ match all rows ending with love
. Any character
L. E matches a string starting with l followed by two characters and then with E.
* Repeat the characters between 0 and multiple asterisks.
A * matches 0 or multiple A strings
[] Any one that matches a group of characters
[Ll] ove matches the string of love or love
[X-y] matches a character in the specified range
[A-Z] ove matches strings starting with an uppercase character followed by ove
[^] Match characters not in the specified group
[^ A-Z] match any character that is not capital
\ Escape characters are used to escape metacharacters
Love \. Matches the character of love followed by.
! Invert
+ Indicates one or more
Xyz + one or more Z
? Zero table or one
XYZ? 0 or one Z
Re metacharacters
\ <First separator \ <love matches words starting with love
|> Love \> matches the word ending with love
\ <Bin \> match a word
\ (.. \) Tags matching characters
(LOV) Able \ 1er/mode lov is saved as label 1, represented by \ 1
Search for a string lov and keep up with Able. Then follow the lov and connect it to er, that is, lovablelover.
The characters X {m}, X {M,}, and X {m, n} repeat: m times, at least m times, at least m times, not more than N times
O {5, 10} matches 5 ~ 10 o strings
| Or
Echo "Tom and Jerry" | sed-r's/(Tom) and (Jerry)/\ 2 and \ 1 /'
Echo "Tom G1, G2, G3 Jerry" | cut-d ""-F2
Echo "ABC Def" | sed-r's/([A-Z] +) ([A-Z] +)/\ 2 \ 1 /'
Echo "ABC Def" | sed-r's/([a-Z0-9] +) ([a-Z0-9] +)/\ 2 \ 1 /'
Echo "abcgood" | grep-e "ABC (good) *" -- color matches ABC with one or more good rows.
Echo "abchidhn" | sed-r's/(.) (. *)/\ 1/'cut characters ()
Echo "ABC" | grep-e "ABC {3}" {} character C appears three times
Echo "ABC defd XYZ" | grep-e "\ <[A-Z] {3} \>" matches three letters
Echo "ABC" | grep-e "ABC +" -- color
Grep-e "^ root | ^ Tom"/etc/passwd
Echo "ABC [email protected] Def" | grep-e "[a-Z0-9. _] [email protected] [a-Z0-9.] + \. [A-Z] {2, 3}
"-- Color
PS: Host =$ (/bin/hostname)
Assign the result of the command execution in () to the host variable.
Grep awk SED is designed based on regular expressions
The regular expression is caused by double quotation marks.
650) This. width = 650; "src =" http://img.baidu.com/hi/face/ I _f45.gif "alt =" I _f45.gif "/> SED loops through a row of processing files
Sed-n'/ABC/P' file prints the content of the mode space by default.
-R supports extending the delimiter, and-N does not allow the default print mode space.
Sed '/ABC/P' file1
Read the first line of file1 to pattern space (temporary buffer, memory)
Perform the/ABC/P operation on this line in pattern space.
Print this line in pattern Space
Clear pattern Space
Read the next row of file1 to pattern Space
Sed [email protected] SED's/ABC/DEF 'file modify the file content after remote Logon
Sed-N '5' file prints the fifth line
Sed-n' $ P' file prints the last row
Sed-n'1, 3 p 'file prints one to three rows
Sed-n' 1 ,~ 3 P 'file: Print three rows starting from the first line
Sed-n'1p; 3p 'file prints the first and third rows
Sed-N '1,/DEF/P' file is printed from the first line until all lines that encounter def are printed.
Sed-I '3i aaaaaaa' file is added to the front of Row 3 with aaaaaaa
Sed-I '$ A AAAAA' file is added to AAAAA in the last line
Sed-I '/^ Tom/I aaaaaa' file adds aaaaaa to the first line of the line starting with Tom
Sed-I's/ABC/DEF/'file to change the first ABC of each row to def
Sed-I's/ABC/DEF/G' file to convert all the ABC values in each row to def
Sed-I's/ABC/DEF/3' file to change the third ABC of each row to def
Sed-I '1, 2 S/ABC/DEF/'file to change one or two lines of ABC to def
Sed-I '1, 2 S/^. * $/DEF/'file to change one or two lines to def
Sed-I '4c aaaaaaaaaaa' file to change row 4 to aaaaaaaa
Sed-I '/^ SELinux/C SELinux' change all rows starting with SELinux to SELinux
Sed-I '/^ ABC/S/Tom/Jerry/' file first finds the line whose Tom starts with ABC and changes it to Jerry
Sed-I '/ABC/,/^ DEF/S/123/456/' file: Change 123 of the row between the row starting with ABC and the row starting with Def to 456
S for the Matched Field C for the matched row
Sed-I '4d 'deletes row 4
Sed-I '/^ Tom/d' file deletes all rows starting with Tom
Sed-I '/^ $/d' file to delete empty rows
Sed-I '/^ \ S $/d' File Deletion starts with an empty row. \ s indicates a space or a tab.
Sed-I '/^ Mike/S/^/#' file comments the Mike line
Sed 's3s/ABC/DEF/; 5S/ABC/YYY/G' file1
Sed's/ABC/DEF/; S/hij/XYZ/'file1
Sed-I-e '1s/Jerry/Tom/;-E 3 S/Mike/XYZ/'run multiple files together with-e
Sed '/ADDR/S/^/#/' add the first row of file1 #
Sed '/ADDR/S/^ # //' file1 first line #
Sed-ri/^ # servername. *: 80 $/S/^ # // etc/SELinux/config
Find the rows starting with # servername and ending with: 80 in the/etc/seliunx/config file
And replace # With Blank
& Save the search string to reference it in the replacement string
Sed's/Tom/& Jerry/'file1
Range matching
Sed '/ABC/,/XYZ/S/Tom/Jerry/' file1 ABC to XYZ
Sed '/Tom/,/Jerry/d' file1
Sed-n'/ABC/,/XYZ/P' file1
Sed '1,/Tom/d' file1 1st rows to 1st rows matching Tom
Reference variable
Var1 = "root"
Sed "/$ var1/C aixocm" file1
Sed-ri "/ipaddr/S/[0-9.] +/$ IP/" ifcfg-eth0
Sed-I "s | ^ $ {I} 1 * | # & |"/etc/fstab
#------------------------------------------------------------------------
650) This. width = 650; "src =" http://img.baidu.com/hi/face/ I _f40.gif "alt =" I _f40.gif "/> awk line-by-line processing field loop command
By default, space is used as the delimiter. The entire line is printed by default. $0-F indicates the delimiter.
Awk 'in in {print "aaaa"}/Tom/{print $2} end {print "bbbbbbb"} 'file1
First, execute the statements in begin to read the first line from the file, and check whether the match exists./If yes, the statement is not executed.
After reading, run the end statement to select the Eng in matching item Eng.
Awk '/^ Mike/{print $2}' file
Awk 'nr = 2 {print $2} 'file nr is the number of NF fields in the row number
Awk 'nr = 2 | Nr = 4 {print $2} 'file read-only two fixed row numbers
Awk '{print $0}' file $0 entire row
Awk 'bengin {FS = ":" OFS = ""}/bash $/{print $0} 'file
FS specifies the delimiter
OFS specifies the output field delimiter
TR ":" "change the colon to a space
Awk 'in in {I = 10; echo $ I }'
Awk-V V1 = $ A-V v2 = $ B 'begin {print V1 + V2}' to pass the bash value to awk
Awk-F:-V V1 = $ a' $0 ~ V1 '{print $0 }~ Matching condition
Awk 'in in {I = 0 ;}{ I ++} end {print I} 'file
Awk '/^ root/{$3 + = 10; print $3}' file
Awk '$1 ~ "Root" {print $1} 'file
Awk '$1 = 500 {print $1}' the first field of file is 500
Awk '$ NF ~ "Bash" {print $1} 'Whether the last field of file has Bash
Awk '$3> = 500 & $3 <= 503 {print $2}' file
Awk-F:-V V1 = $ a' $1 ~ ^ V1 'file: print the rows starting with variable.
Awk-F: '{if ($1 ~ /^ Root/) Print $1} 'file prints the first field of the row whose first field starts with Root
Next, read the next row directly.
Continue
Exit is over and cannot be read
Break
INT () Integer
Awk 'System ("useradd" $2) 'file system () call the system command
DF-th | grep "/$" | awk '{print $6}' | SED's/% //'
After DF, truncate a field and replace it.
650) This. width = 650; "src =" http://img.baidu.com/hi/face/ I _f39.gif "alt =" I _f39.gif "/> TR for character operations, single character processing tools, rather than string processing tools
Cat file1 | TR "ABC" "XYZ"
Replace a with X, B with Y, and C with Z instead of ABC.
Echo "ABC 11a22bc" | TR "ABC" "XYZ" Result: XYZ 11x22yz
TR "ABC" "XYZ" <File Processing File
TR "a-z" "A-Z" <file converts lowercase letters to uppercase letters
TR ":" "\ m"
Echo "abdcdd" | tr-d "ABC" deletes three ABC characters
Cat file | tr-D "A-Z"
Echo "aaaaaaxcxxx cccccccc" | tr-s "ABC" compresses repeated ABC characters into one character
650) This. width = 650; "src =" http://img.baidu.com/hi/face/ I _f45.gif "alt =" I _f45.gif "/> sort sorting file not changed
By default, blank space is used as the delimiter to sort by the first field (sort by string ASIC)
Sort-N file is ordered by the value of the first field.
Sort-r Reverse Order
Sort-K2 is arranged in the Second Field
Sort-T: separate fields:
Sort-T:-k3nr/etc/passwd
Note: first sort and then uniq
650) This. width = 650; "src =" http://img.baidu.com/hi/face/ I _f39.gif "alt =" I _f39.gif "/> uniq to repeat rows without changing the file
Uniq file only changes adjacent duplicate rows
Uniq-C displays the number of adjacent duplicate rows.
Uniq-u only displays rows with no adjacent duplicates
650) This. width = 650; "src =" http://img.baidu.com/hi/face/ I _f40.gif "alt =" I _f40.gif "/> cut delimiter default Delimiter is the tab key
Cut-D:-f1-f3 file specifies the delimiter as long as 1 3 Field
Cut-D:-F1, 3, 5
Echo "addfgg" | cut-C3 takes the third character
650) This. width = 650; "src =" http://img.baidu.com/hi/face/ I _f39.gif "alt =" I _f39.gif "/> grep
Grep-n "root"/etc/passwd filter out and Add rows
The row number filtered out by grep-c "root"/etc/passwd
Grep-V "root"/etc/passwd
Grep-Q "root"/etc/passwd filtered out not displayed
Grep-W "root"/etc/passwd: filter the row with the word root.
Grep-o "root"/etc/passwd filter out the root word
The grep-ro "root" directory filters out the root lines in the files in the directory.
Grep-I "root"/etc/passwd ignore case sensitivity
Grep-e "root"/etc/passwd enable extended Regular Expressions
Grep-F file file1 filters out the rows that are shared by file and file1.
Grep-F file file1-V: filter the rows in which file has no file1
Grep-X "root" file: filters the rows containing only root in the file.
650) This. width = 650; "src =" http://img.baidu.com/hi/face/ I _f38.gif "alt =" I _f38.gif "/> Find
Find.-nouser: Find out files without a master
Find. + size + Objective C find the file with more than 10000 bytes
Find/-maxdepth 1-name "*. conf"-maxdepth will not find the sub-File
Find.-Perm 600: Find the 600 permission
Find.-Name "*. Sh" | xargs Rm-RF {} finds the file and submits it to RM for processing.
Find.-Name "*. Sh" | xargs-I {} Rm-RF {} Use-I to specify the content to be found. 4
650) This. width = 650; "src =" http://img.baidu.com/hi/face/ I _f40.gif "alt =" I _f40.gif "/> trap shielding Signal
Trap ''2 shields the interrupt signal and does nothing
Trap 'ls; PWD; date' 2 when the start interrupt signal (CTRL + C) executes ls; PWD; date;
Trap 2 Restoration
650) This. width = 650; "src =" http://img.baidu.com/hi/face/ I _f45.gif "alt =" I _f45.gif "/> curl
The curl-O a.html http://www.sohu.com/index.html downloads the first page of the searchbody to a.html
Curl-O http://www.sohu.com/index.html will download the home page of Sohu
Curl-T file ftp: // 10.0.2.253/upload the file to 10.0.2.253 using the FTP protocol
This article from the "Love armed for a lifetime" blog, please be sure to keep this source http://menglinux.blog.51cto.com/8733806/1437330