Karl Karl - 1 year ago 93
Linux Question

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

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. I have old version of awk 3.1

Answer Source

GNU awk has inplace modification option, if you have 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"' _ {} \;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download