Linux基础10_正则表达式及扩展

来源:互联网 发布:滑窗的方法 数据分析 编辑:程序博客网 时间:2024/06/07 05:41

[:alnum:] 代表英文大小写字节及数字,亦即 0-9, A-Z, a-z

[:alpha:]  代表任何英文大小写字节,亦即 A-Z, a-z

[:blank:]  代表空白键与 [Tab] 按键两者

[:cntrl:]   代表键盘上面的控制按键,亦即包括 CR, LF, Tab, Del.. 等等

[:digit:]      代表数字而已,亦即 0-9

[:graph:]  除了空白字节 (空白键与 [Tab] 按键) 外的其他所有按键

[:lower:]  代表小写字节,亦即 a-z

[:print:]   代表任何可以被列印出来的字节

[:punct:]  代表标点符号 (punctuation symbol),亦即:" ' ? ! ; : # $...

[:upper:] 代表大写字节,亦即 A-Z

[:space:]  任何会产生空白的字节,包括空白键, [Tab], CR 等等

[:xdigit:]  代表 16 进位的数字类型,因此包括: 0-9, A-F, a-f 的数字与字节

 

搜索特定字符:

dmesg | grep -n --color=auto‘eth’       列出核心信息,并搜寻‘eth’

grep –n ‘the’express.txt           在express.txt这个文件中搜索the

grep –vn ‘the’express.txt          反向选择

grep –in ‘the’express.txt          无论大小写输出

 

用[ ]来搜寻集合

grep –n ‘t[a-z]st’express.txt       搜寻t?st

grep –n ‘[^g]o’express.txt        找带有o的字符,但前一个不是g

grep –n ‘[^a-z]o’express.txt       找o字符,但前一个不是小写字母

grep –n ‘[^[:lower:]]o’express.txt   找o字符,但前一个不是小写字母

grep –n‘[[:digit:]]’ express.txt     找到有数字的那行

 

任意一个字节

grep –n ‘g..d’express.txt            搜寻g??d, 一个点代表一个字符

grep –n ‘g*d’express.txt        搜寻g*d

*代表任意个字符

grep –n‘go\{2,5\}’ express.txt    搜寻g后面重复2-5次o的字符串,反斜杠起转义作用

 

nl passwd | sed‘2d’            将passwd内容展示,并删除第二行

nl passwd | sed ‘3cNONONONO’  将第三行取代为NONONONONO

nl passwd | sed –n‘4,6p’         显示第4-6行

 

ifconfig eth0 |grep ‘inet addr’    查询网卡inet addr(或其他)信息



egrep-n ‘go+d’ express.txt   搜寻god,good,goood…

egrep -n‘go?d’ express.txt  搜寻有一个或零个o

 

egrep-n ‘gd|good’ express.txt  

搜寻gd或者good, |

 

egrep-n ‘g(la|oo)d’ express.txt

搜寻glad或good



以及练习文档:

"OpenSource" is a good machanism to develop programs.

Basketball game isnot use hand only.

This dress doesn'tfit me.

However, thisdress is about $2939 dollars.*N

GUN is free airnot free beer.*N

Her hair is verybeauty.*N

I can't finish thetest.

The window isclear.

oh! My god!

You are the best.

I like the dog.

go! go! Let's go!

The soup tastegooe.


0 0
原创粉丝点击