【发布时间】:2010-05-12 17:16:01
【问题描述】:
在我的 shell 脚本中,我尝试使用在 $sourcefile 中找到的术语一遍又一遍地针对同一个 $targetfile 进行搜索。
我的 $sourcefile 格式如下:
pattern1
pattern2
etc...
我必须搜索的低效循环是:
for line in $(< $sourcefile);do
fgrep $line $targetfile | fgrep "RID" >> $outputfile
done
我知道可以通过将整个 $targetfile 加载到内存中或使用 AWK 来改进这一点?
谢谢
【问题讨论】:
-
你能不能只加入源文件和 egrep for (pattern1|pattern2...)?
-
好主意...不过需要 egrep 来获得 4000 个选项...模式会根据源文件中的行数而有所不同。