# #正则表达式特殊字符解析
"^" |
Match beginning |
"$" |
Match end of Line |
"^$" |
Match whole behavior empty, empty line grep-v "^$" print a non-empty line |
"." |
Represents and can only represent any one character |
"*" |
Repeat 0 or more characters in front of each other. such as "o*", repeat one or more O |
".*" |
Matches all characters. Extend: "^.*"-starts with any number of characters. ". *$"-ends with any number of characters |
"\" |
Let the characters that have special meanings, take off the vest, restore the prototype. For example, "\.", which means "." Only. Point itself |
"[ABC]" |
Matches any one of the characters in the brackets in "[]" |
"[^ABC]" |
Matches the contents of any character that does not contain "^", that is, the match does not contain "a" | B "|" C "Content |
(1) "A\{n,m\}" (2)"a\{n,\}" (3) "a\{n\}" (4)"a\{,m\}" |
(1) match the previous character, repeat n->m the content, Egrep/sed-r or grep-e can save \ Escape. The "a" character repeats N to m of the content match (2) The previous character repeats at least n times (3) repeat n times for the previous character (4) The first character repeats at most m times. Will be a repeat 0-m times content matching |
# #实例1#实战准备
Mkdir-p/root/test0513/
Adjust Character set: Exportlc_all=c or echo "Exportlc_all=c" >>/etc/profile && source/etc/profile
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/87/3F/wKioL1fY9Z6x64KLAABAxeTmLIg911.png-wh_500x0-wm_3 -wmp_4-s_1926252077.png "title=" combat preparation. png "alt=" wkiol1fy9z6x64klaabaxetmlig911.png-wh_50 "/>
Grep-n "^m" Oldboy.log print lines beginning with M grep-n "m$" Oldboy.log print lines ending in M grep-n "^$" Oldboy.log print Blank lines grep-nv "^$" Oldboy . log printing of non-empty rows
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/87/3F/wKioL1fY9gnSqRbUAABkrtRgOVk866.png "title=" The beginning ends with the. png "alt=" Wkiol1fy9gnsqrbuaabkrtrgovk866.png "/>
grep "." Oldboy.log prints a line that contains any character, that is, the blank line does not contain characters, and does not print grep ". *" Oldboy.log any character repeats 0-n times, that is, all print all Lines grep ". *$" Oldboy.log print with any character Ends, and repeats 0-n times, including blank lines grep "^.*" Oldboy.log printing starts with any character and repeats 0-n times, including blank lines grep "old.*y" Oldboy.log print lines with any characters between old and y grep "0*" O Ldboy.log printing contains rows that repeat 0 times to any number of times 0
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/87/42/wKiom1fY9k6yzvQJAADDfVmARH8708.png-wh_500x0-wm_3 -wmp_4-s_1161263483.png "title=" repeats n times. png "alt=" wkiom1fy9k6yzvqjaaddfvmarh8708.png-wh_50 "/>
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/87/3F/wKioL1fY90ri5L2yAAAXvp7BgNA413.png-wh_500x0-wm_3 -wmp_4-s_2222012395.png "title=" matches any. png "alt=" wkiol1fy90ri5l2yaaaxvp7bgna413.png-wh_50 "/>
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/87/42/wKiom1fY922BTnUJAABTtlZ5DME913.png-wh_500x0-wm_3 -wmp_4-s_2416595876.png "title=" repeat 0 to you. png "alt=" wkiom1fy922btnujaabttlz5dme913.png-wh_50 "/>
grep "[A-z]" Oldboy.log print all line grep "[^a-z]" containing lowercase letters A-Z oldboy.log print all lines that do not contain a A-Z, negative
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/87/42/wKiom1fY957ApFAXAABn-1-yrHM134.png-wh_500x0-wm_3 -wmp_4-s_1331579872.png "title=" Print range. png "alt=" wkiom1fy957apfaxaabn-1-yrhm134.png-wh_50 "/>
grep "0\{1,9\}" Oldboy.log print 0 characters repeat 1-9 times line grep "0\{3\}" Oldboy.log 0 repeats 3 times line grep "0\{,3\}" Oldboy.log 0 repeats 0-3 times row grep " 0\{4,\} "Oldboy.log 0 repetitions of more than 4 rows
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/87/42/wKiom1fY-2bBuKRuAAAUwmbRoH8263.png "title=" 1dao9ci.png "alt=" Wkiom1fy-2bbukruaaauwmbroh8263.png "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/87/40/wKioL1fY-2bhXuIQAAAVLPeUmhQ602.png "title=" 3 times. png "alt=" Wkiol1fy-2bhxuiqaaavlpeumhq602.png "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/87/40/wKioL1fY-2bQN10iAAAzBbhlNqQ959.png "title=" 0 to 4 times. png "alt=" Wkiol1fy-2bqn10iaaazbbhlnqq959.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/87/42/wKiom1fY-2fCpihuAAAQD-4VmDI289.png "title=" Repeat more than 4 times. png "alt=" Wkiom1fy-2fcpihuaaaqd-4vmdi289.png "/>
# #实例2: Remove ifconfigeno167 of the NIC IP Address
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/87/3F/wKioL1fY-P3RkGd0AABGcxGqVv8551.png "title=" Nic information. png "alt=" Wkiol1fy-p3rkgd0aabgcxgqvv8551.png "/>
(1) SED regular match + back reference
Ifconfig eno16777736|sed-n ' 2p ' |sed ' s#^.*inet # #g ' |sed ' s# net.*$# #g ' ifconfig eno16777736 |sed-n ' 2 ' P |sed-r ' s#^.*ine T (. *) #\1#g ' |sed-r ' s# (. *) netmask.*$#\1#g ' ifconfig eno16777736 |sed-n ' 2 ' P |sed-r ' s#^.*inet (. *) Netm.*$#\1#g ' Ifconfi G Eno16777736|sed-nr ' 2s#^.*inet (. *) NETMASK.*$#\1#GP '
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/87/42/wKiom1fY-YHRGg_pAAA4bqQUqnU197.png "title=" SED regular match 1.png "alt=" Wkiom1fy-yhrgg_paaa4bqquqnu197.png "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/87/3F/wKioL1fY-YHz_nkuAAAVKNxFyKc996.png "title=" SED regular match 2.png "alt=" Wkiol1fy-yhz_nkuaaavknxfykc996.png "/>
(2)awk
Ifconfig eno16777736|sed-n ' 2p ' |awk ' {print $} ' ifconfig eno16777736 |awk ' nr==2{print $} '
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/87/3F/wKioL1fY-f2zHVynAAAWR9dTTDg216.png "title=" Awk1.png "alt=" Wkiol1fy-f2zhvynaaawr9dttdg216.png "/>
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/87/42/wKiom1fY-f3hdcmZAAAVtELwkfc153.png "title=" Awk2.png "alt=" Wkiom1fy-f3hdcmzaaavtelwkfc153.png "/>
Regular expression parsing & Awk/sed/grep Practical Example Summary document