首页 > 系统服务 > 详细

Linux中Grep常用的15个例子

时间:2014-04-02 08:05:12      阅读:637      评论:0      收藏:0      [点我收藏+]

Grep命令主要用于从文件中查找指定的字符串。

首先建一个demo_file:

$ cat demo_file
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.

Two lines above this line is empty.
And this is the last line.

例01:从单个文件中查找指定的字符串

$ grep "this" demo_file
this line is the 1st lower case line in this file.
Two lines above this line is empty.

例02:从多个文件中查找指定的字符串

$ cp demo_file demo_file1

$ grep "this" demo_*
demo_file:this line is the 1st lower case line in this file.
demo_file:Two lines above this line is empty.
demo_file:And this is the last line.
demo_file1:this line is the 1st lower case line in this file.
demo_file1:Two lines above this line is empty.
demo_file1:And this is the last line.

例03:忽略大小写使用 grep -i

$ grep -i "the" demo_file
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.
And this is the last line.

例04:


例05:

例06:

例07:

例08:

例09:

例10:

例11:

例12:

例13:

例14:

例15:

原文链接http://www.thegeekstuff.com/2009/03/15-practical-unix-grep-command-examples/

Linux中Grep常用的15个例子,布布扣,bubuko.com

Linux中Grep常用的15个例子

原文:http://blog.csdn.net/jerry_1126/article/details/22760653

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!