繁体   English   中英

在unix中搜索包含特定字符串的文件

[英]Search for files containing specific string in text file in unix

我是编写shell脚本的新手,想在目录中搜索扩展名为“* RETURN.DAT”的文件中的特定字符串。 我想要查找的字符串位于单独的文件中。 我应该使用什么unix命令? 我使用find和grep混淆了。 我还需要复制我在另一个目录中找到的文件。 提前致谢。

如果文件目录中你不需要findman 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM