Soumettre la recherche
Mettre en ligne
4, grep
•
1 j'aime
•
462 vues
ted-xu
Suivre
About linux grep tool
Lire moins
Lire la suite
Signaler
Partager
Signaler
Partager
1 sur 8
Recommandé
Tcpdump的使用简介
Tcpdump的使用简介
lifeibo
Command line 初級寶典
Command line 初級寶典
Tom Chen
Windbg入门
Windbg入门
晓锋 陈
Golang
Golang
popeast
C python 原始碼解析 投影片
C python 原始碼解析 投影片
kao kuo-tung
A brief introduction to Python
A brief introduction to Python
bugway
Golangintro
Golangintro
理 傅
Linq 入门
Linq 入门
greenerycn
Recommandé
Tcpdump的使用简介
Tcpdump的使用简介
lifeibo
Command line 初級寶典
Command line 初級寶典
Tom Chen
Windbg入门
Windbg入门
晓锋 陈
Golang
Golang
popeast
C python 原始碼解析 投影片
C python 原始碼解析 投影片
kao kuo-tung
A brief introduction to Python
A brief introduction to Python
bugway
Golangintro
Golangintro
理 傅
Linq 入门
Linq 入门
greenerycn
7, reusing classes
7, reusing classes
ted-xu
Handleiding Forecast Solution Shared
Handleiding Forecast Solution Shared
Daan Blinde
Harsh Pershad (Innovate UK) presenting 'Funding Opportunities from Innovate U...
Harsh Pershad (Innovate UK) presenting 'Funding Opportunities from Innovate U...
UK Carbon Capture and Storage Research Centre
01 Gedda Jfk2009
01 Gedda Jfk2009
Pierre Trudelle
Copia de experiencia de aula
Copia de experiencia de aula
olguita1975
Informatie, Middel Voor Gezonde Sturing
Informatie, Middel Voor Gezonde Sturing
Daan Blinde
2, object oriented programming
2, object oriented programming
ted-xu
cv
cv
SRIJAN ROY
Каталог Bravolli
Каталог Bravolli
Grigory Grigorev
Master Genzyme Presentation
Master Genzyme Presentation
engelske
Formation Gestalt IFFP 2017
Formation Gestalt IFFP 2017
Institut Français de Formation Psychocorporelle
Seo in raipur
Seo in raipur
Deepak Nagraj
три дерева - Three Trees
три дерева - Three Trees
Freekidstories
Welcome To Deep Tissue Massage
Welcome To Deep Tissue Massage
William Burton LMT CMCE
11, OCP - awr & alert system
11, OCP - awr & alert system
ted-xu
10, OCP - flashback
10, OCP - flashback
ted-xu
9, OCP - restore and recovery with rman
9, OCP - restore and recovery with rman
ted-xu
8, OCP - backup with rman
8, OCP - backup with rman
ted-xu
7, OCP - configure database for backup and recovery
7, OCP - configure database for backup and recovery
ted-xu
6, OCP - oracle security
6, OCP - oracle security
ted-xu
5, OCP - oracle storage
5, OCP - oracle storage
ted-xu
4, OCP - oracle networking
4, OCP - oracle networking
ted-xu
Contenu connexe
En vedette
7, reusing classes
7, reusing classes
ted-xu
Handleiding Forecast Solution Shared
Handleiding Forecast Solution Shared
Daan Blinde
Harsh Pershad (Innovate UK) presenting 'Funding Opportunities from Innovate U...
Harsh Pershad (Innovate UK) presenting 'Funding Opportunities from Innovate U...
UK Carbon Capture and Storage Research Centre
01 Gedda Jfk2009
01 Gedda Jfk2009
Pierre Trudelle
Copia de experiencia de aula
Copia de experiencia de aula
olguita1975
Informatie, Middel Voor Gezonde Sturing
Informatie, Middel Voor Gezonde Sturing
Daan Blinde
2, object oriented programming
2, object oriented programming
ted-xu
cv
cv
SRIJAN ROY
Каталог Bravolli
Каталог Bravolli
Grigory Grigorev
Master Genzyme Presentation
Master Genzyme Presentation
engelske
Formation Gestalt IFFP 2017
Formation Gestalt IFFP 2017
Institut Français de Formation Psychocorporelle
Seo in raipur
Seo in raipur
Deepak Nagraj
три дерева - Three Trees
три дерева - Three Trees
Freekidstories
Welcome To Deep Tissue Massage
Welcome To Deep Tissue Massage
William Burton LMT CMCE
En vedette
(14)
7, reusing classes
7, reusing classes
Handleiding Forecast Solution Shared
Handleiding Forecast Solution Shared
Harsh Pershad (Innovate UK) presenting 'Funding Opportunities from Innovate U...
Harsh Pershad (Innovate UK) presenting 'Funding Opportunities from Innovate U...
01 Gedda Jfk2009
01 Gedda Jfk2009
Copia de experiencia de aula
Copia de experiencia de aula
Informatie, Middel Voor Gezonde Sturing
Informatie, Middel Voor Gezonde Sturing
2, object oriented programming
2, object oriented programming
cv
cv
Каталог Bravolli
Каталог Bravolli
Master Genzyme Presentation
Master Genzyme Presentation
Formation Gestalt IFFP 2017
Formation Gestalt IFFP 2017
Seo in raipur
Seo in raipur
три дерева - Three Trees
три дерева - Three Trees
Welcome To Deep Tissue Massage
Welcome To Deep Tissue Massage
Plus de ted-xu
11, OCP - awr & alert system
11, OCP - awr & alert system
ted-xu
10, OCP - flashback
10, OCP - flashback
ted-xu
9, OCP - restore and recovery with rman
9, OCP - restore and recovery with rman
ted-xu
8, OCP - backup with rman
8, OCP - backup with rman
ted-xu
7, OCP - configure database for backup and recovery
7, OCP - configure database for backup and recovery
ted-xu
6, OCP - oracle security
6, OCP - oracle security
ted-xu
5, OCP - oracle storage
5, OCP - oracle storage
ted-xu
4, OCP - oracle networking
4, OCP - oracle networking
ted-xu
3, OCP - instance management
3, OCP - instance management
ted-xu
2, OCP - installing and creating a database
2, OCP - installing and creating a database
ted-xu
1, OCP - architecture intro
1, OCP - architecture intro
ted-xu
12, OCP - performance tuning
12, OCP - performance tuning
ted-xu
7, business event system
7, business event system
ted-xu
6, workflow miscellaneous
6, workflow miscellaneous
ted-xu
5, workflow function activity
5, workflow function activity
ted-xu
4, workflow tables & api
4, workflow tables & api
ted-xu
3, workflow in ebs
3, workflow in ebs
ted-xu
2, a simple workflow
2, a simple workflow
ted-xu
1, workflow intro
1, workflow intro
ted-xu
8, bes tables & api
8, bes tables & api
ted-xu
Plus de ted-xu
(20)
11, OCP - awr & alert system
11, OCP - awr & alert system
10, OCP - flashback
10, OCP - flashback
9, OCP - restore and recovery with rman
9, OCP - restore and recovery with rman
8, OCP - backup with rman
8, OCP - backup with rman
7, OCP - configure database for backup and recovery
7, OCP - configure database for backup and recovery
6, OCP - oracle security
6, OCP - oracle security
5, OCP - oracle storage
5, OCP - oracle storage
4, OCP - oracle networking
4, OCP - oracle networking
3, OCP - instance management
3, OCP - instance management
2, OCP - installing and creating a database
2, OCP - installing and creating a database
1, OCP - architecture intro
1, OCP - architecture intro
12, OCP - performance tuning
12, OCP - performance tuning
7, business event system
7, business event system
6, workflow miscellaneous
6, workflow miscellaneous
5, workflow function activity
5, workflow function activity
4, workflow tables & api
4, workflow tables & api
3, workflow in ebs
3, workflow in ebs
2, a simple workflow
2, a simple workflow
1, workflow intro
1, workflow intro
8, bes tables & api
8, bes tables & api
4, grep
1.
grep
2.
Agenda
3.
概述 • grep命令用于在查找指定的模式, 并且输出
出匹配该模式的行, grep命令的输入可以是 文件/标准输入/管道, 其中管道是指将另一 个命令的结果作为grep命令的输入, 这很常 见; • grep命令衍生了很多其他的变种, 比如 egrep/fgrep等, 这里只介绍基本的grep命令.
4.
用法说明 • grep命令使用如下格式:
1, grep pattern file1 file2... 从一个或者多个文件中查找模式并且输出; 如果指定了多个文件 则会首先输出文件名称, 然后输出匹配行. 2, command | grep pattern 从其他命令的输出中查找模式并打印; 3, grep pattern 在标准输入中查找模式并打印. • 示例: grep hello textfile # 查找textfile包含hello的行 ls | grep .*txt # 查找当前目录下文件名以txt结尾的 所有文件 grep hello # 用户每输入一行就对该行进行匹配, 如果该行包含hello则打印 • 注意: 使用grep命令时, 最好使用引号将需要匹配的模式括起来.
5.
元字符 & 命令选项 •
grep命令使用的正则表达式元字符基本上与vim的相 同, 具体可以参考vim元字符《 3, Regular Expression.pptx 》 • grep命令有如下常用选项: -c 仅打印匹配的行数, 不打印行的内容 -i 模式匹配时忽略大小写 -h 不显示文件名称 -l 仅列出匹配文件的文件名, 每个文件仅列出一次, 文件名之间使用换行符分隔 -n 在输出的每一行前加上该行在文件中的行号 -v 显示不匹配的行
6.
退出状态 • grep命令在执行完成时, 会设置一个程序退
出状态码, 使用$?查看. 如果找到了匹配相应 模式的行, 状态为0; 如果没有找到则设置为 1, 如果查找的文件不存在则设置为2. 示例:
7.
用法示例 • 示例:
grep ‘<Tom>’ file # 输出包含单词Tom的行 grep ‘Tom Savage’ file # 输出包含Tom Savage的行 grep ‘^Tommy’ file # 输出以Tommy开头的行 grep ‘.bak$’ file # 输出以.bak结尾的行 grep ‘[Pp]yramid’ * # 输出当前目录所有文件包含 Pyramid或pyramid的行 grep ‘[A-Z]’ file # 输出至少包含一个大小字母的行 grep ‘[0-9]’ file # 输出至少包含一个数字字符的行 grep -v ‘Mary’ file # 输出所有不包含Mary的行 grep -i ‘sam’ file # 输出包含sam的行, 不区分大小写 grep -l ‘Dear Boss’ * # 列出所有包含Dear Boss的文件名 grep -n ‘Tom’ file # 输出包含Tom的行, 并加上行号 grep “$name” file # 展开变量name的值, 然后输出所有 包含该值的行 ps -ef | grep ‘^ *user1’ # 查找user1用户的进程
8.
END