【发布时间】:2020-01-07 21:45:35
【问题描述】:
要查找包含我使用的两个字符串的文件,
grep -l "$string1" `grep -l "$string2" /path/to/files/*.txt`
下面是示例输入的完整描述
脚本测试.sh
#!/bin/bash
string1="hello"
string2="good"
string3="world"
grep -l "$string1" `grep -l "$string2" /path/to/files/*.txt`
file1.txt
hi
good morning
everyone
file2.txt
hello everyone
good morning world
have a great day
file3.txt
hola
good day today
hello people
sunny morning
运行脚本的输出:
/path/to/files/file2.txt
/path/to/files/file3.txt
【问题讨论】:
-
您发布的脚本和您接受的答案都找不到包含 3 个字符串的文件。问题中甚至没有说明您对此类问题通常遇到的各种重要场景的要求是什么。如果您想要针对此问题的可靠解决方案,请发布一个新问题。
标签: bash