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

linux命令——Grep 命令 用法大全的更多相关文章

  1. linux管道命令grep命令参数及用法详解---附使用案例|grep

    功能说明:查找文件里符合条件的字符串. 语 法:grep [-abcEFGhHilLnqrsvVwxy][-A<显示列数>][-B<显示列数>][-C<显示列数>] ...

  2. 12个 Linux 中 grep 命令的超级用法实例

    12个 Linux 中 grep 命令的超级用法实例 你是否遇到过需要在文件中查找一个特定的字符串或者样式,但是不知道从哪儿开始?那么,就请grep来帮你吧. grep是每个Linux发行版都预装的一 ...

  3. linux中grep命令的使用

    转载:http://blog.csdn.net/universsky/article/details/8866402 linux中grep命令的使用 grep (global search regul ...

  4. linux中grep命令的用法

    作为linux中最为常用的三大文本(awk,sed,grep)处理工具之一,掌握好其用法是很有必要的. 首先谈一下grep命令的常用格式为:[grep  [选项]  "模式"  [ ...

  5. linux命令-grep+正则表达式用法

    目标文件/etc/passwd,使用grep命令或egrep 1.显示出所有含有root的行:egrep 'root' passwd 2.输出任何包含bash的所有行,还要输出紧接着这行的上下各两行的 ...

  6. 由一条Linux的grep命令说起

    今天在开发的时候,看到同事使用了这样的一条linux命令 grep 'class YourClass' -rwi * |grep -v svn 想到了 grep命令的,几个参数. -r 明确要求搜索子 ...

  7. Linux之grep命令详解

    简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它 ...

  8. Linux的grep命令详解

    简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它 ...

  9. Linux中grep命令学习

    1.简介 grep是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来.Unix的grep家族包括grep.egrep和fgrep.egrep和fgrep的命令只跟grep有很小 ...

  10. 【转】【Linux】grep命令详解

    简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它 ...

随机推荐

  1. 根据标点符号分行,StringBuilder的使用;将字符串的每个字符颠倒输出,Reverse的使用

    一:根据标点符号分行,上图,代码很简单 二:代码 using System; using System.Collections.Generic; using System.ComponentModel ...

  2. [已解决问题] An error occurred while automatically activating bundle com.android.ide.eclipse.adt

    可以参见stackoverflow的解决方案:http://stackoverflow.com/questions/16974349/an-error-occurred-while-automatic ...

  3. php微信支付接口开发程序(一)

    阅读对象 本文阅读对象:商户系统(在线购物平台.人工收银系统.自动化智能收银系统或其他)集成微信支付涉及的技术架构师,研发工程师,测试工程师,系统运维工程师. 支付模式 1. 刷卡支付 刷卡支付是用户 ...

  4. 火球-UML大战需求分析(体验版3.0.2).pdf

    火球-UML大战需求分析(体验版3.0.2).pdf http://files.cnblogs.com/files/happlyonline/%E7%81%AB%E7%90%83-UML%E5%A4% ...

  5. UML学习之类图

    參考链接: http://www.uml.org.cn/oobject/201211231.asp  深入浅出UML http://www.open-open.com/lib/view/open132 ...

  6. TextView的ems和MaxLength

    <EditText android:id="@+id/et_code" android:layout_width="wrap_content" andro ...

  7. Fragment 回退栈 传递参数,点击切换图片使用Fragment ListView

    Fragment回退栈  类似与Android系统为Activity维护一个任务栈,我们也可以通过Activity维护一个回退栈来保存每次Fragment事务发生的变化. 如果你将Fragment任务 ...

  8. Swift: 继承

    为了在属性值改变的时候获得通知,类可以为继承的属性添加属性观察者.属性观察者可以添加到任何属性上,不管这个属性原来是存储属性还是计算属性. Swift中的类没有一个统一的基类. 为了讲明白继承,我们先 ...

  9. YYCache 源码分析(一)

    iOS 开发中总会用到各种缓存,YYCache或许是你最好的选择.性能上有优势,用法也很简单.作者ibireme曾经对比过同类轮子:http://blog.ibireme.com/2015/10/26 ...

  10. ios创建的sqlite数据库文件如何从ios模拟器中导出

    为了验证数据库的结构,有的时候需要使用一些管理工具来直接查看sqlite数据库的内容,在windows下有sqlite3的专用工具下载,而在ios下也可以使用火狐浏览器的插件sqlitemanager ...