linux中grep支持的正则表达式


 

grep 最强大之处:

        支持正则表达式

  grep [options]  'pattern' files

  examples:

  grep --color  'root'   /etc/passwd  在用户信息中搜索包含‘root’ 字符的行

  notes1:grep 有很多参数,其中常见的有-i

  ex:grep --color  -i  '[a-zA-Z0-9]'    path

  grep  --color  -v  'pattern'   path  显示除了匹配到之外的行

  notes2:元字符

  ^匹配行首

  $匹配行尾

  \<定位首字符串

  >/定位尾字符串

  x\{m\}

  examples:有这样一系列字符串root  ,troot ,you are root  ,rootable is ,wo

  grep  --color   "^r"  path 结果root  ,rootable is

  grep  --color    "t$'  path  结果   root  ,troot,you are root

  grep  --color   "\<r" path 结果root  ,you are root  ,rootableis

  grep  --color   "t>/" path 结果root ,troot,you are  root

  grep  --color  "0\{2\}"path 结果  root,troot ,you are root ,rootable  is

相关内容

    暂无相关文章