简体   繁体   English

如何使用find命令对多个文件执行awk脚本

[英]How can i execute awk script with find command on multiple files

This command is working fine for me for single file 对于单个文件,此命令对我而言工作正常

awk -f test.awk template.yml file.yml > tmp && mv tmp file.yml

The fins command i have find all files i want fins命令我找到了我想要的所有文件

find . -wholename "*vars/*.yml"

I am not sure how can i execute above awk command on all files so that they can get replaced in place. 我不确定如何在所有文件上执行以上awk命令,以便可以将它们替换到位。 I have old version of awk 3.1 我有AWK 3.1的旧版本

GNU awk has inplace modification option, if you have GNU awk : 如果您有GNU awk ,则GNU awk具有就地修改选项:

find . -wholename "*vars/*.yml" -exec awk -i inplace -f test.awk {} +

Otherwise, you need to handle the files one at a time: 否则,您需要一次处理一个文件:

find . -wholename "*vars/*.yml" -exec \
     bash -c 'awk -f test.awk "$1" >"$1".tmp && mv "$1".tmp "$1"' _ {} \;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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