码迷,mamicode.com
首页 > 其他好文 > 详细

grep常用用法

时间:2015-03-31 22:21:16      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:files   grep   

grep简介

正如linux的man文件中所描述的那样:

   grep  searches  the  named  input  FILEs (or standard input if no files are named, or if a single hyphen-minus (-) is given as file name) for lines containing a match to the given PATTERN.  By default, grep prints the matching lines.
   In addition, two variant programs egrep and fgrep are available.  egrep is the same as grep -E.   fgrep  is  the  same  as  grep -F.   Direct invocation as either egrep or fgrep is deprecated, but is provided to allow historical applications that rely on them to run unmodified.

grep是用来在一个文件中查找和给定的模式相匹配的行的命令,同时egrep 和 fgrep都已经被弃用,取而代之的是 grep -E和grep -F。

使用方法

在单个文件中搜索包含字符串的行

语法:
grep “literal_string” filename

在多个文件中搜索包含字符串的行

语法:
grep “this” demo_*
注:这个的搜索域是demo_为前缀的文件

使用 -i 参数可以实现大小写无关

可以使用正则表达式来过滤

语法:
grep “REGEX” filename

具体使用方法可以参考:http://www.cnblogs.com/kuyuecs/archive/2012/07/13/2589988.html
写得很不错的博客。

grep常用用法

标签:files   grep   

原文地址:http://blog.csdn.net/ivyvae/article/details/44785711

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!