Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在unix中从文件列表中搜索单词/词组_Unix_Grep_Find - Fatal编程技术网

在unix中从文件列表中搜索单词/词组

在unix中从文件列表中搜索单词/词组,unix,grep,find,Unix,Grep,Find,我想搜索给定文件夹中所有文件中出现的单词,并仅查看文件列表。我已尝试:- find-类型f-exec grep-l{}\ 但是我得到了所有出现的关键字的整行。有点乱了 我还尝试了grep-hr.但是这个选项是:grep:unliqued option--r 请帮忙。不确定您的grep有什么问题,但这很好: find . -type f -exec grep -l the {} \; ./br.csv ./combined.csv ./skyscan.csv ./skyscan.db ./team

我想搜索给定文件夹中所有文件中出现的单词,并仅查看文件列表。我已尝试:-
find-类型f-exec grep-l{}\
但是我得到了所有出现的关键字的整行。有点乱了

我还尝试了
grep-hr.
但是这个选项是:grep:unliqued option--r


请帮忙。

不确定您的
grep有什么问题,但这很好:

find . -type f -exec grep -l the {} \;
./br.csv
./combined.csv
./skyscan.csv
./skyscan.db
./team.sql
./uniq.js

也许可以检查您正在运行的
grep

您真的在命令中包含
字符吗?那会把事情搞砸的。使用诸如
oneWord
“two words”
之类的文字字符串或变量,即
“$1”
,或
“$myVar”
。祝你好运。@Sheller:-没有Sheller。。这是为了解释。我使用的是
oneword
我认为你做得对,你的问题不明显。对于初学者,我要确认
/bin/grep-l'knowntextinfle'/path/to/one/fileWithKnownText
text按预期工作。如果这样做有效,但上面仍然会导致问题,那么
find-f | xargs grep-l'oneWord'
类型在过去曾多次对我有效。假设你的操作系统有xargs。祝你好运