注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

zorksylar

Nothing is impossible , if distributed.

 
 
 

日志

 
 

【linux】【bash】Regular expressions  

2012-04-14 17:55:25|  分类: linux学习 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
cited :  《Bash Guide for Beginners》 Machtelt Garrels


【linux】【bash】Regular expressions - sylareclipse - sylar


1.output the line number

grep -n root /etc/passwd


2.display the lines without the 'root'

grep -v root /etc/passwd


3.counts the number of line with 'root'

grep -c root /etc/passwd


4.ignore case 

grep -i root /etc/passwd


5.lines start with 'root' 

grep ^root /etc/passwd


6.lines ends with 'root'

grep root$ /etc/passwd


7.words starts with 'PATH' , ie, 'MANPATH' will not be displayed

grep '\<PATH' /etc/profile


end with 'PATH' 

grep '\>PATH' /etc/profile


8.find a single word (enclosed by spaces)

grep -w / /etc/fstab


9. '.' for single character match

list 5 char word starting with 'c' and ending with 'h' 

grep '<c...h>' /usr/share/dict/words


10.find '*' (asterisk) 

grep '*' /etc/profile



11.about '[  ]' , means a list
matches any single character in the list []
if the first character of the list is '^' , it matches any character NOT in the list
if two characters separated by '-' ,it's a range expression, matches any single character that
sorts between the two characters , inclusive, using the locale's collating sequence and character set.

[a-d] is equivalent to [abcd] or [aBbCcDd] , it depends on the locale's  collating sequence. [abcd] is the default C locale.
set LC_ALL environment varibale to C ,to use the C locale

  评论这张
 
阅读(79)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018