#!/bin/bash
echo"This is a test!" | sed -n '/test/p'#This is a test! echo"This is a tests!" | gawk '/test/{print $0}'#This is a tests! 部分匹配 echo"This is a test!" | sed -n '/ /p'#This is a test! 空格==字符#以下特殊字符需要加\转义echo"This is * " | sed -n '/\*/p'#This is * echo"This is [] " | sed -n '/\[/p'#This is [] echo"This is ^ " | sed -n '/\^/p'#This is ^echo"This is $ " | sed -n '/\$/p'#This is $echo"This is {} " | sed -n '/{/p'#This is {} echo"This is \ " | sed -n '/\\/p'#This is \ echo"This is / " | sed -n '/\//p'#This is /echo"This is + " | sed -n '/\+/p'#This is + echo"This is ? " | sed -n '/\?/p'#This is ?echo"This is | " | sed -n '/\|/p'#This is |echo"This is () " | sed -n '/)/p'#This is () echo"this is a test@" | sed -n '/^this/p'#this is a test@ 头部匹配echo"haha , this is a test@" | sed -n '/^this/p'#不匹配echo"@this is a test" | sed -n '/test$/p'#@this is a test 尾部匹配 echo"@this is a tests" | sed -n '/test$/p'#不匹配 #sed '/^$/d' file #删除file文件中的空行echo"this is a cat" | sed -n '/.at/p'#this is a cat 必须匹配一个字符echo"this is a at" | sed -n '/.at/p'#this is a at 该字符可为空格echo"heow" | sed -n '/hel*ow/p'#heow 0次/多次 echo"hellllow" | sed -n '/hel*ow/p'#hellllow 0次/多次 echo"HEow" | gawk '/HEl?ow/{print $0}'#HEow 0次/1次echo"HElow" | gawk '/HEl?ow/{print $0}'#HElow 0次/1次echo"HEllow" | gawk '/HEl?ow/{print $0}'#不匹配 echo"fuccck" | gawk '/uc+k/{print $0}'#fuccck 1次/多次 echo"fuak" | gawk '/u[ac]+k/{print $0}'#fuak 1次/多次 字符组匹配 echo"fuk" | gawk '/u[ac]+k/{print $0}'#不匹配 1次/多次 echo"cao" | gawk --re-interval '/ca{1}o/{print $0}'#cao 仅出现1次 echo"caaaao" | gawk --re-interval '/ca{1,3}o/{print $0}'#不匹配 出现1~3次,此处4次echo"Yes" | sed -n '/[Yy][Ee]s/p'#Yes 字符组匹配,可接受大小写格式 echo"this is 3p,hoho!" | sed -n '/[0123]p/p'#this is 3p,hoho!echo"213300" | sed -n '/[0-9][0-9][0-9][0-9][0-9]/p'#213300 区间匹配 echo"313300" | sed -n '/^[0-9][0-9][0-9][0-9][0-9]$/p'#数字个数不匹配 只能5个数字echo"p1331" | sed -n '/[^0-9][0-9][0-9][0-9][0-9]/p'#p1331 排除字符组,首字符不能为数字echo"p1332" | sed -n '/[0-9][0-9][0-9][0-9][0-9]/p'#不匹配 首位不为数字 echo"p1333" | sed -n '/[a-z][0-9][0-9][0-9][0-9]/p'#p1333 首位为字母echo"Hi,4 !" | sed -n '/[[:alnum:]]/p'#Hi,4 ! 任意字母/数字:0-9 a-z A-Z echo"Hi,1 !" | sed -n '/[[:alpha:]]/p'#Hi,1 ! 任意字母: a-z A-Z echo"Hi,2 !" | sed -n '/[[:lower:]]/p'#Hi,2 ! 任意小写字母: a-z echo"Hi,3 !" | sed -n '/[[:upper:]]/p'#Hi,3 ! 任意大写字母: A-Z echo"Hi,6 !" | sed -n '/[[:digit:]]/p'#Hi,6 ! 任意数字: 0-9 echo"Hi,5 !" | sed -n '/[[:blank:]]/p'#Hi,5 ! 空格echo"Hi,7 !" | sed -n '/[[:space:]]/p'#Hi,7 ! 空格 echo"Hi,8 !" | sed -n '/[[:punct:]]/p'#Hi,8 ! 标点符号echo"Hi,9 !" | sed -n '/[[:print:]]/p'#Hi,9 ! 可打印字符echo"The cat is asleep" | gawk '/cat|dog/{print $0}'#The cat is asleep 管道匹配echo"The cog is asleep" | gawk '/cat|[dc]og/{print $0}'#The cog is asleep 管道+字符数组匹配echo"Sat" | gawk '/Sat(urday)?/{print $0}'#Sat 聚合,接收完整名或者缩写名echo"Saturday" | gawk '/Sat(urday)?/{print $0}'#Saturday