您的位置:首页 > 编程语言

通过文件内容,输出符合条件的文件名

2017-05-26 10:46 274 查看
找出当前目录下所有含"aop"字符的文件,去掉脚本自己的名字,注意使用sh执行这儿脚本,否则,用./1.sh调用,过滤的是./1.sh,而不是1.sh
[root@VM_48_191_centos 456]# cat 1.sh
#!/bin/bash
for i in `ls`
do
m=`cat $i|grep aop`
if [ -n "$m" ]
then
echo "$i" >>/root/456/6.txt
fi
done
cat /root/456/6.txt | grep -v $0

也可以直接使用grep -l
[root@VM_48_191_centos 456]# grep -l 'aop' ./*
./1.sh
./1.txt
./3.txt
./4.txt
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  脚本编程
相关文章推荐