1

I want to replace all occurrences of {{password}} or {{ password }} or {{password }} in files with some string using sed i am able to remove with know number of spaces , but could not remove all combinations.

i could replace using , but not all combinations

sed -i -e "s/{{ password }}/$password/g" test.sql
2
  • note that you'll have to make sure password variable doesn't contain \ or & or the delimiter character which / in the example used above.. see also: stackoverflow.com/questions/29613304/… Commented May 26, 2020 at 8:26
  • 1
    also, as a good practice, I'd use 's/{{ password }}/'"$password"'/g' to avoid double quotes conflicting with sed command Commented May 26, 2020 at 8:27

1 Answer 1

3

If the number of spaces is arbitrary, then you could search for zero or more spaces (*) instead of just one space () with something like {{ *password *}}.

Sign up to request clarification or add additional context in comments.

1 Comment

if you are using regex, I often use "\s" instead of " " just to be sure there are not tabs or other whitespace characters "posing" as a regular space.

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.