2

I have a yaml file that I am trying to create a number within a loop and replace it with the newly computed variable.

The line i wish to replace looks like this:

 # genesis_gas_limit:            "16000000" ## Used to set genesis gas limit

I plan on putting this in a loop and thus I would love it if the sed could take a wild card i.e.

 # genesis_gas_limit:            "*" ## Used to set genesis gas limit

I have have tried this

sed -i 's/ genesis_gas_limit:/c\ genesis_gas_limit: $GASLIMIT' examples/values-local.yaml

but i get the following error:

sed: 1: "examples/values-local.yaml": invalid command code e

I would appreciate any pointers on this

1

1 Answer 1

1

You could replace genesis_gas_limit: and whatever content follows it, with genesis_gas_limit: and the new value. Using GNU sed:

sed -i "s/ genesis_gas_limit:.*/ genesis_gas_limit: \"$GASLIMIT\"/" examples/values-local.yaml

Using BSD sed (in OSX):

sed -i.bak -e "s/ genesis_gas_limit:.*/ genesis_gas_limit: \"$GASLIMIT\"/" examples/values-local.yaml
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks fro your help. From this site i gathered i need to include "" to the sed command ed.gs/2016/01/26/os-x-sed-invalid-command-code. When i use it with your answer , it doesnt error. however, it doesnt substitute the string in the file. do you . know what might be wrong?
when i used sed -e it does replace the line, but doesnt substitute the variable
@SamuelDare are you using GNU or BSD version of sed? (Look at your man sed)
using an OSX so BSD
@SamuelDare BSD sed has a slightly different syntax for editing files in place. Its -i option requires a backup extension parameter; if you don't want to make a backup, you must explicitly supply an empty parameter after -i (that is, sed -i "" instead of just sed -i). In your original command, BSD sed will interpret the entire 's/ ... will be taken as the backup extension, and it'll try to interpret examples/values-local.yaml as the sed command to execute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.