[英]Use search terms from awk to grep and output to separate search term specific files
我有一堆通过 awk 生成的搜索词 - 每行一个 uuid。
我想为这些 uuid 和 output 的每个输入文件 grep 为每个 uuid 分隔 output 文件。
例如:
awk.output:
uuid1
uuid2
uuid3
file.input:
this is uuid1
this is uuid2
this is uuid3
desired files -
uuid1.output:
this is uuid1
uuid2.output:
this is uuid2
uuid3.output:
this is uuid3
没有任何 shell 脚本的简洁方法是什么? 就像使用 awk、grep 和重定向操作一样。
可能不适用于特殊输入...:D
xargs -a awk.input -d "\n" -I {} sh -c 'grep "${1}" file.input > "${1}.output"' -- {}
awk
可以 append 到文件使用
print items >> output-file
所以,你可以有类似的东西
awk 'FILENAME == "awk.output" {uuids[$1]++} FILENAME != "awk.output" { for (u in uuids) { if ($0 ~ u) {print >> (u ".output")}}} ' awk.output file.input
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.