grep使用

grep常用的使用方法

grep –rns “match_content”filename 查看匹配内容的行

find /path –name “*.h” –o –name “*.cpp” | xargs grep –rn “match_content”在特定的文件类型中查找

grep –rns “match_content” –A10 –B10 filename > logfile  将匹配到的行的附近内容输入到其他文件

grep –w “match_content”filename  精确匹配

grep –I “match_content” filename 不区分大小写匹配

grep –v “match_content” filename 显示不包含匹配文本的其他行

grep -f<范本文件> 指定范本文件,其内容有一个或多个范本样式,让grep查找符合范本条件的文件内容,格式为每一列的范本样式

eg:同时匹配包含"how are you"或者"I am fine"类似的多个字符串,在程序调试时可以过滤自己关注的全部关键字,特别有用!!!

     grep -f match.pat < filename

-f<范本文件> 指定范本文件,其内容有一个或多个范本样式,让grep查找符合范本条件的文件内容,格式为每一列的范本样式

来自: http://man.linuxde.net/grep
原文地址:https://www.cnblogs.com/zhouLee/p/4738249.html