-2

I need to change 's3_bucket': 'pass' to hello but it is not working

ex: echo "'s3_bucket': 'pass'" | sed 's/'s3_bucket':/hello/' outputs:
's3_bucket': 'pass'

Please help understand what am I doing wrong

  • Is your data literally the output from `echo`, or are you working with a text file? Is that text file in JSON, YAML, or HCL format? Modifying a document with `sed` when that document format requires special encoding of data is not really encouraged. There are special tools for working with that sort of data. Also, are you actually _querying_ the document with a password, or do you just want to modify all instances of the `s3_bucket` key? – Kusalananda Jan 31 '22 at 15:38

1 Answers1

3

The quoting is wrong. The part 's/'s3_bucket':/hello/' is interpreted by the shell as 's/' followed by s3_bucket and ':/hello/', resulting in s/s3_bucket:/hello/ as an argument for sed.

Try

echo "'s3_bucket': 'pass'" | sed "s/'s3_bucket':/hello/"

or

echo "'s3_bucket': 'pass'" | sed 's/'\''s3_bucket'\'':/hello/'

Note that in the second version there are two adjacent single quotes in '\'', not a double quote.

There are more possible ways of quoting, see this answer to a similar question.

Bodo
  • 5,979
  • 16
  • 27