From c6537a9d669ab5c0f3de35e2cf40232b2c7ee27f Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Tue, 10 Jan 2023 13:53:54 +1100 Subject: [PATCH] added update multiple files tips --- usage/tips-and-tricks.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/usage/tips-and-tricks.md b/usage/tips-and-tricks.md index 3fb30497..d0b71749 100644 --- a/usage/tips-and-tricks.md +++ b/usage/tips-and-tricks.md @@ -55,6 +55,16 @@ The `strenv` operator is a great way to handle special characters in strings: VAL='.a |!@ == "string2"' yq '.a = strenv(VAL)' example.yaml ``` +## Update multiple files + +`yq` doesn't have a way of updating multiple files in a single command (yet?) - but you can use your shell's built in tools like `find`: + +``` +find *.yaml -exec yq '. += "cow"' -i {} \; +``` + +This will run the `'. += "cow"'` expression against every matching file, and update it in place (`-i`). + ## String blocks and newline issues There are a couple of tricks to getting the right string representation, take a look at [string operators](https://mikefarah.gitbook.io/yq/operators/string-operators#string-blocks-bash-and-newlines) for more details: