1、 参数:
-I :忽略大小写
-c :打印匹配的行数
-l :从多个文件中查找包含匹配项
-v :查找不包含匹配项的行
-n:打印包含匹配项的行和行标

2、RE(正则表达式)
\ 忽略正则表达式中特殊字符的原有含义
^ 匹配正则表达式的开始行
$ 匹配正则表达式的结束行
\< 从匹配正则表达式的行开始
\> 到匹配正则表达式的行结束
[ ] 单个字符;如[A] 即A符合要求
[ - ] 范围 ;如[A-Z]即A,B,C一直到Z都符合要求
. 所有的单个字符
* 所有字符,长度可以为0

3、举例
# ps -ef | grep in.telnetd
root 19955 181 0 13:43:53 ? 0:00 in.telnetd

# more size.txt size文件的内容
b124230
b034325

# more size.txt | grep '[a-b]' 范围 ;如[A-Z]即A,B,C一直到Z都符合要求
b124230
b044525

# more size.txt | grep '[a-b]'*
b124230
b034325

# more size.txt | grep 'b' 单个字符;如[A] 即A符合要求
b124230
b034325

# more size.txt | grep '[bB]'
b124230
b034325
b103303

# grep 'root' /etc/group
root::0:root
bin::2:root,bin,daemon
sys::3:root,bin,sys,adm
adm::4:root,adm,daemon
uucp::5:root,uucp
mail::6:root
tty::7:root,tty,adm
lp::8:root,lp,adm
nuucp::9:root,nuucp
daemon::12:root,daemon


# grep '^root' /etc/group 匹配正则表达式的开始行
root::0:root

# grep 'uucp' /etc/group
uucp::5:root,uucp
nuucp::9:root,nuucp

# grep '\<uucp' /etc/group
uucp::5:root,uucp

# grep 'root$' /etc/group 匹配正则表达式的结束行
root::0:root
mail::6:root

# more size.txt | grep -i 'b1..*3' -i :忽略大小写
b124230
b103303
B103303

# more size.txt | grep -iv 'b1..*3' -v :查找不包含匹配项的行

b034325
a081016

# more size.txt | grep -in 'b1..*3'
1:b124230

# grep '$' /etc/init.d/nfs.server | wc -l
128
# grep '\$' /etc/init.d/nfs.server | wc –l 忽略正则表达式中特殊字符的原有含义

15
# grep '\$' /etc/init.d/nfs.server
case "$1" in
>/tmp/sharetab.$$
[ "x$fstype" != xnfs ] &&

# more size.txt

the test file
their are files
The end

# grep 'the' size.txt
the test file
their are files

# grep '\<the' size.txt
the test file
their are files

# grep 'the\>' size.txt
the test file

# grep '\<the\>' size.txt
the test file

# grep '\<[Tt]he\>' size.txt
the test file

最新文章

  1. MVC 区域功能
  2. PHP 二维数组根据相同的值进行合并
  3. Django: TemplateDoesNotExist at /admin/
  4. SSH连接不上Linux的解决方法
  5. EasyTouch 3.1中文翻译
  6. Windows 系统版本判断
  7. IOS设计模式学习(19)策略
  8. Js验证 :只能输入数字和小数点 验证是否是数字 js取float型小数点后两位
  9. apache、php隐藏http头部版本信息的实现方法
  10. Vue CLI 3.0脚手架如何在本地配置mock数据
  11. bat执行python脚本,执行多条命令
  12. 区别samtools faid产生的.fai文件功能和bwa index 产生的四个文件的功能
  13. Netty简单聊天室
  14. js获取height和width总结
  15. css3 transition(转换)笔记
  16. Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layou
  17. 2-R型聚类
  18. 线上CPU飚高(死循环,死锁...)
  19. 如何得知 kernel 或 android 已開機多久時間
  20. js运算符、关键字、保留字、转义字符

热门文章

  1. datetime和timer的使用(小小幻灯片)
  2. Final对象
  3. HDOJ(HDU) 2161 Primes(素数打表)
  4. 在VC中集成cURL
  5. UVA 11922 Permutation Transformer(Splay Tree)
  6. 【转】Linux下查看所有用户及用户组
  7. 网络编程之TCP异步群聊:服务器端代码
  8. 将对象格式的style转换为字符串格式
  9. 提升ReSharper和Visual Studio的性能
  10. 限制 UITextField 输入长度