Skip to content

Instantly share code, notes, and snippets.

@jclosure
Created January 8, 2022 02:30
Show Gist options
  • Save jclosure/8e1c34f0588bd77367790f6ea488d6fe to your computer and use it in GitHub Desktop.
Save jclosure/8e1c34f0588bd77367790f6ea488d6fe to your computer and use it in GitHub Desktop.
modify yaml on the fly as part of a make task
UNAME := $(shell uname)
###
#
# assuming a yaml like this:
# main:
# device: 21
#
###
# semantic parsing and changing of the yaml
set-device-mode:
ifeq ($(UNAME), Linux)
if ! command -v yq &> /dev/null ; then \
wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64; \
chmod a+x /usr/local/bin/yq; \
fi
endif
yq e -i '.main.device = 22' ./params.yaml
run: set-device-mode
echo "starting program"
@jclosure
Copy link
Author

jclosure commented Jan 8, 2022

Test replacement regex matches easily in shell:

sed -E 's/(\s+device:\s)(21)/\122/g' ./spiff_params/params.yaml  | diff params.yaml -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment