grep的简单的用法
2016-05-05 17:35
441 查看
演示文件:
1
-A表示匹配本行和之后的行
2
-B表示匹配本行和之前的行
3
-C表示 匹配本行与上下行
4
-c表示grep的参数有多少个
5
–color表示颜色显示
6
-e后面跟正则表达式,可以跟多个正则
7
-f指定文件内容作为查询条件
8
-m 最多匹配多少个个数作为条件
9
-n表示行数计数
10
-o 只打印匹配的内容
11
-R搜素子目录内容
12
-v表示查找不含参数的行
13
w查找一个词
[root@cyf opt]# cat 123.txt qqqqqqqqqq wwwwwwwww eeeeeeeeeaa rrrrrr aaaaa 111 222 333 4 5 a
1
-A表示匹配本行和之后的行
[root@cyf opt]# grep -A 1 111 123.txt 111 222
2
-B表示匹配本行和之前的行
[root@cyf opt]# grep -B 1 111 123.txt aaaaa 111
3
-C表示 匹配本行与上下行
[root@cyf opt]# grep -C 1 222 123.txt 111 222 333
4
-c表示grep的参数有多少个
[root@cyf opt]# grep -c a 123.txt 3
5
–color表示颜色显示
[root@cyf opt]# grep --color 11 123.txt 111
6
-e后面跟正则表达式,可以跟多个正则
[root@cyf opt]# grep -e ^e -e 2$ 123.txt eeeeeeeeeaa 222
7
-f指定文件内容作为查询条件
[root@cyf opt]# cat we 11 [root@cyf opt]# ls 123.txt we [root@cyf opt]# grep -f we 123.txt 111
8
-m 最多匹配多少个个数作为条件
[root@cyf opt]# cat 123.txt qqqqqqqqqq wwwwwwwww eeeeeeeeeaa rrrrrr aaaaa 111 222 333 4 5 a[root@cyf opt]# grep -m 2 a 123.txt
eeeeeeeeeaa
aaaaa
9
-n表示行数计数
[root@cyf opt]# grep -n a 123.txt 3:eeeeeeeeeaa 5:aaaaa 11:a
10
-o 只打印匹配的内容
[root@cyf opt]# grep -o 11 123.txt 11 [root@cyf opt]# grep -o 1 123.txt 1 1 1
11
-R搜素子目录内容
[root@cyf opt]# grep -R a * 1/2/3/spur:aaaaa 123.txt:eeeeeeeeeaa 123.txt:aaaaa 123.txt:a we:a
12
-v表示查找不含参数的行
[root@cyf opt]# grep -v a 123.txt qqqqqqqqqq wwwwwwwww rrrrrr 111 222 333 4 5
13
w查找一个词
[root@cyf opt]# cat we a 12 33 44 55 66 77 a s d f [root@cyf opt]# grep -w 12 we 12 33 44
相关文章推荐
- 自定义View解析之自定义View实战(四)
- formatDate-------date、datetime型数据用EL表达式在页面显示
- HP-UX /usr/lib/dld.sl: Can't open shared library:解决办法
- iOS每日一记——————————iOS开发当中的一些技巧
- 【面试笔试】程序设计基础
- eclipse如何使用快捷键实现编辑窗口放大还原
- Android 使用ContentProvider扫描手机中的图片,仿微信显示本地图片效果
- php脚本配置
- jQuery常用及基础知识总结(一)
- android在线API文档
- Telnet与SSH两大协议的区别
- web应用性能优化经验总结
- C++第五次剩余项目—数组选择(非实验和作业)
- LeetCode 136: Single Number
- 二十六 使用枚举类
- iOS,Android,Jave后台AES加密解密
- Axis2创建WebService实例
- 关于软件重用的思考
- 利用arping发广播包
- android:TextView中的文本链接之--链接的几种方式