正则表达式
示例1(新建名为grep.txt文件)
ooxx12121212ooxx ooxx 12121212 oox 12121212 1212 ooxx 1212 oo3xx oo4xx ooWxx oomxx $ooxx oo1234xx ooxyzxx
键入如下命令
grep "(^[0-9]|[^0-9][0-9])[0-9]{2}([0-9][^0-9]|[0-9]$)" grep.txt grep -E "^[0-9]{4}[^0-9]|[^0-9][0-9]{4}[^0-9]|[^0-9][0-9]{4}$|^[0-9]{4}$" grep.txt
示例2(新建test文件)
aaabbcaaa
aa bbc aaa
bb bbc bbb
asgodssgoodsssagodssgood
asgodssgoodsssagoodssgod
sdlkjflskdjf3slkdjfdksl
slkdjf2lskdjfkldsjl
键入如下指令
cat test 51 grep "a" test 52 grep "a{3}" test 53 grep "<aaa" test 54 grep "<aaa>" test 55 grep "b" test 56 grep "b{2,3}" test 57 clear 58 cat test 59 grep "god" test 60 grep "godgood" test 61 grep "god*good" test 62 grep "god.*good" test 63 grep "god.*good.*god.*good" test 64 grep "god.*good+" test 65 grep "(god.*good)+" test 66 grep "(god).*good.*1" test 67 grep "(god).*(good).*1.*2" test 68 vi test 69 grep "(god).*(good).*1.*2" test 70 grep "(god).*(good).*2.*1" test