我只想列出使用Linux命令包含字符串的文件名。
当使用egrep时,会显示字符串的所有实例,这可能是倍数。
例如,:
egrep disco music_file*.txt可能会出现;
music_file1.txt: blah blah blah disco stuff
music_file1.txt: disco blah blah blah
music_file1.txt: I like to listen to italodisco
music_file2.txt: I like to party to disco
music_file3.txt: Does your dog like disco?而我只想要:
music_file1.txt
music_file2.txt
music_file3.txt问题:在Linux中搜索字符串时,如何才能显示每个文件名的一个实例?
发布于 2013-09-09 09:11:04
将-l添加到egrep表达式中:
egrep -l disco music_file*.txt来自man grep
-l,-有匹配的文件 禁止正常输出;相反,请打印输出通常会从其中输出的每个输入文件的名称。扫描将在第一场比赛中停止。(-l由POSIX.)
发布于 2013-09-09 09:12:27
grep -l应该适合您。
grep -l pattern files*.txt来自手册页:
-l, --files-with-matches
Suppress normal output; instead print the name of each input
file from which output would normally have been printed. The
scanning will stop on the first match. (-l is specified by
POSIX.)https://stackoverflow.com/questions/18694928
复制相似问题