Madura Dissanayake
Madura Dissanayake

Reputation: 8739

How to replace values which are in single quotes using a bash script?

Hello I have a text file called "sampleText.txt" which includes string line like this,

subscribe_key =  'sub-c-xx-xx-xx-xx-xx';

What I need is I need to change this subscribe_key value using bash script. So the given below bash script I used bt it did not work. Hope You will help me to let it work, Any help would be greatly appreciated. Thank You.

#!/bin/bash

sed -i.bak -r '/^subscribe_key/{s/"[^']+'"/"sub-c-123-456-789"/}' sampleText.txt

Upvotes: 2

Views: 66

Answers (1)

sat
sat

Reputation: 14949

You can use this sed,

sed -i.bak -r "/^subscribe_key/s/([^']+')([^']+)('.*)/\1sub-c-123-456-789\3/" yourfile

Upvotes: 1

Related Questions