我有一个名为lookupfile.txt的文件,其中包含以下信息:
路径,包括文件名
在bash中我想在mylookup file.txt中搜索这些文件以获取模式:myerrorisbeinglookedat。找到后,将找到的行输出到另一个记录文件中。所有找到的结果都可以存放在同一个文件中。
请帮忙。
答案 0 :(得分:0)
您可以编写单个grep
语句来实现此目的:
grep myerrorisbeinglookedat $(< lookupfile.txt) > outfile
假设:
否则:
while IFS= read -r file; do
# print the file names separated by a NULL character '\0'
# to be fed into xargs
printf "$file\0"
done < lookupfile.txt | xargs -0 grep myerrorisbeinglookedat > outfile
xargs
获取循环的输出,正确标记它们并调用grep
命令。 xargs
根据操作系统限制批量处理文件,以防有大量文件。