Skip to content

Instantly share code, notes, and snippets.

@ajaxray
Last active June 13, 2022 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajaxray/5314953f3818a890fce72b74c1c44f08 to your computer and use it in GitHub Desktop.
Save ajaxray/5314953f3818a890fce72b74c1c44f08 to your computer and use it in GitHub Desktop.
Shell script to update a yaml configuration using sed
echo "Replacing FB Access Token"
echo "--------------------\n"
# Displaying old value for reference
echo "### Old configuration"
grep ' access_token:' config.yml
echo "### New configuration"
echo " access_token: \"$1\""
sed -i "" "s/^\s+access_token: .*$/ access_token: \"${1}\"/" config.yml
echo "\nDone.\n"
@ajaxray
Copy link
Author

ajaxray commented Aug 24, 2021

This is a shell script to update yaml configuration using sed tool.
It's replacing value of access_token in config.yml in current directory as example.
The configuration key and file path should be adjusted according to your scenario.

How to use

sh update_token.sh the-new-token-to-set

@avatar-lavventura
Copy link

Can it be done without providing any input argument and the set value would be embedded?

@durganava
Copy link

could you please share the config.yml file for reference

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