Pavel Zagalsky
Pavel Zagalsky

Reputation: 1636

Failure replacing URL pattern with sed

I am attempting to change 1 URL in a config file with another using sed and I fail for different reasons. The URL I am trying to replace is:

#define API_PRODUCTION @"https://api.mything.com/v2.0/services"

with:

#define API_PRODUCTION @"https://qaapp3.mything.com/20151115_apiv2/services"

I tried escaping with \ before every / and different methods but failed for "unterminated substitute pattern" or for " bad flag in substitute command: 'a'" Seems so easy, yet I cannot nail it. Thanks in advance!

Upvotes: 2

Views: 644

Answers (2)

hd1
hd1

Reputation: 34657

% sed -ie s/api/qapp3/ filename.txt define API_PRODUCTION @"https://qapp3.mything.com/v2.0/services"

I'm on NetBSD, so your sed may be different, Pavel.

Upvotes: 1

falsetru
falsetru

Reputation: 369064

You don't need to escape / if you use another character as separator:

$ cat testfile
#define API_PRODUCTION @"https://api.mything.com/v2.0/services"
$ sed -e 's,https://api.mything.com/v2.0/services,https://qaapp3.mything.com/20151115_apiv2/services,' testfile
#define API_PRODUCTION @"https://qaapp3.mything.com/20151115_apiv2/services"

Upvotes: 4

Related Questions