One - One Code All

Blog Content

linux grep过滤不包含某些字符串的命令

Linux-Mac 运维   2010-09-04 15:37:31

grep常用用法


grep [-acinv] [--color=auto] '搜寻字符串' filename

选项与参数:

-a :将 binary 文件以 text 文件的方式搜寻数据

-c :计算找到 '搜寻字符串' 的次数

-i :忽略大小写的不同,所以大小写视为相同

-n :顺便输出行号

-v :反向选择,亦即显示出没有 '搜寻字符串' 内容的那一行!

--color=auto :可以将找到的关键词部分加上颜色的显示喔!


举个例子,我需要提取不含ok的行并统计对应的行数


grep -cv "OK" result


或者


grep -v "OK" result |wc -l


显示不含ok的行和行数


grep -nv "OK" result



上一篇:linux Shell sort按照指定列排序
下一篇:unzip直接覆盖解压

The minute you think of giving up, think of the reason why you held on so long.