[英]From UNIX shell, how to find all files containing a specific string, then print the 4th line of each file?
[英]Search for files containing specific string in text file in unix
我是编写shell脚本的新手,想在目录中搜索扩展名为“* RETURN.DAT”的文件中的特定字符串。 我想要查找的字符串位于单独的文件中。 我应该使用什么unix命令? 我使用find和grep混淆了。 我还需要复制我在另一个目录中找到的文件。 提前致谢。
如果文件在目录中你不需要find
( man find
: 搜索的目录层次结构的文件 ),而是你可以点grep
从该目录搜索:
$ grep search_term path/to/a/dir/*.DAT
由于你想要查找的字符串是在一个单独的文件中 , man grep
:
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. If this option is used
multiple times or is combined with the -e (--regexp) option,
search for all patterns given. The empty file contains zero
patterns, and therefore matches nothing.
所以:
$ grep -f separate_file path/to/a/dir/*.DAT`
应该做的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.