码迷,mamicode.com
首页 > 系统相关 > 详细

linux 正则匹配小记

时间:2015-07-01 20:46:45      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

1.使用正则匹配文件名

## grep -n ‘[^\/][a-zA-Z0-9]*[.a-zA-Z0-9][a-zA-Z0-9]*$‘ regular_express.txt

/etc/init.d/hello.h

/etc/init.d/hehe



2.使用sed提取出网卡IP  

(1)

# ifconfig eth0 |grep ‘inet addr‘

 inet addr:192.168.211.129  Bcast:192.168.211.255  Mask:255.255.255.0

(2)

# ifconfig eth0 |grep ‘inet addr‘ | sed ‘s/^.*addr://g‘

192.168.211.129  Bcast:192.168.211.255  Mask:255.255.255.0

(3)

# ifconfig eth0 |grep ‘inet addr‘ | sed ‘s/^.*addr://g‘ | sed ‘s/Bcast.*$//g‘

192.168.211.129

3.

(1)过滤‘MAN‘

# cat /etc/man.config |grep -n ‘MAN‘

(2)将以#开头的句子后面内容替换为空

# cat /etc/man.config |grep -n ‘MAN‘ | sed ‘s/#.*$//g‘

11:

17:

18:

19:

39:

41:

43:MANPATH      /usr/man

44:MANPATH      /usr/share/man

45:MANPATH      /usr/local/man

46:MANPATH      /usr/local/share/man

47:MANPATH      /usr/X11R6/man

(3)删除空行

# cat /etc/man.config |grep ‘MAN‘|sed ‘s/#.*$//g‘ | sed ‘/^$/d‘

MANPATH /usr/man

MANPATH /usr/share/man

MANPATH /usr/local/man

MANPATH /usr/local/share/man

MANPATH /usr/X11R6/man


linux 正则匹配小记

标签:

原文地址:http://my.oschina.net/CentralD/blog/473050

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!