grep经常使用使用方法

本文介绍了Linux下的grep命令,它用于在文件中搜索与指定模式匹配的行。文章涵盖了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
写得非常不错的博客。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值