【发布时间】:2015-12-09 16:33:03
【问题描述】:
是否可以告诉 grep 为每种匹配的搜索字符串使用不同的输出文件?
我需要递归搜索所有 *.log 以找到所有“[ERROR]”、“[WARN]”和“[ASSERT]”。但我想让它在不同的输出文件中分开。每个搜索字符串都有一个输出文件。 (无需多次调用 grep!)
搜索已经有效:(从 gmake 调用)
grep -nHr --include=*.log -e '\[ERROR\]' -e '\[WARN\]' -e '\[ASSERT\]' $(root_path) > $(root_path)/result.txt
但由于性能原因,我不想多次调用 grep:
grep -nHr --include=*.log -e '\[ERROR\]' $(root_path) > $(root_path)/result_[ERROR].txt
grep -nHr --include=*.log -e '\[WARN\]' $(root_path) > $(root_path)/result_[WARN].txt
是否有可能以某种方式拥有它:
grep -nHr --include=*.log -e {'PATTERN1' | 'PATTERN2' | 'PATTERN3'} $(root_path) > $(root_path)/result{'PATTERN1'|'PATTERN2'|'PATTERN3'}.txt
【问题讨论】: