通过文件内容,输出符合条件的文件名
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
[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
相关文章推荐
- 联合主键、java直接通过文件名读取文件内容
- as通过gradle实现多渠道打包+使用配置文件进行版本管理+指定apk输出路径和apk文件名
- Shell 命令行 从日志文件中根据将符合内容的日志输出到另一个文件
- 一个简单的文件后缀获取——不是通过文件名,而是文件内容
- 编程题:输入文件名,输出该文件的内容。fgetc(fp)的使用。
- 输入文件名及路径创建该文件,并把从键盘输入的内容保存到该文件,最后将该文件的路径、该文件名及文件中的内容输出到屏幕。
- as通过gradle实现多渠道打包+使用配置文件进行版本管理+指定apk输出路径和apk文件名
- Java+通过XPath获取XML文件中符合特定条件的节点
- 将here doc输出的内容保存到文件,当文件超过阈值,动态更新文件名
- 第四单元 输出重定向及文件名 / 文件内容的字符搜索
- linux grep 查找 匹配 内容的文件 且 输出 文件名
- 如何是获取一个文件夹里所有以.java结尾文件的数目,并把符合条件的文件名写到一个目录下。
- 用cmd的FC命令 对比两个文件夹内容不同并将文件名输出到文件中
- 编写一个函数,能输出文件夹下的文件列表,文件名通过控制台输入
- Linux下父进程通过管道发送文件名给子进程,子进程获取文件名后首先判断文件是否存在,不存在,通过管道返回错误信息,存在,将文件内容返回给父进程
- 编写一个函数,能输出文件夹下的文件列表,文件名通过控制台输入
- as通过gradle实现多渠道打包+使用配置文件进行版本管理+指定apk输出路径和apk文件名
- cat - 接合多个文件并在标准输出打印内容出来
- 通过http/https的POST方式,发送、处理和接收XML文件内容
- 通过 http 协议上传文件(rfc1867协议概述,jsp 应用举例,客户端发送内容构造)