Linux中的grep -v命令
grep -vhttps://blog.csdn.net/whatday/article/details/88872316basenamehttps://www.cnblogs.com/machangwei-8/p/9570202.htmlfindhttps://www.cnblogs.com/whyd/p/11757552.html
·
Linux中的grep -v命令
grep 命令用于查找文件里符合条件的字符串,通常会和cat搭配使用,也是工作中使用比较多的命令语句,比如下面这条语句,会把text.txt文件中包含字符BATCH的行都打印出来。
cat test.sh | grep BATCH
今天在工作中遇到grep -v命令,之前没有用到过,简单记录一下。
grep -v 过滤关键字
#!/bin/bash
# test.sh脚本如下
hello!
hello world!
this is a nice day!
the world is so beautiful!
过滤文本test.sh文件中不包含world的行,并打印出来,可以使用下面这条语句:
cat test.sh | grep -v world
输出结果为:
hello!
this is a nice day!
再举个例子,比如当前文件夹下有很多文件:
需要找出包含test的文件,那么可以直接使用grep:
如果需要过滤出不包含test的文件,那么就可以使用grep -v:
是不是很简单呢,嘻嘻嘻,加油!
更多推荐
已为社区贡献5条内容
所有评论(0)