0

I'm using Amazon Linux. I'm trying to run a search and replace using sed. I'm running into the below error ...

[jboss@mydevbox nodejs]$ sed -i -e "s/test.smokeTest('(.*?)', '(.*?)', '(.*?)')/test.smokeTest('username', 'password', 'http://localhost:8081/myproject')/g" test.js 
sed: -e expression #1, char 96: unknown option to `s'

Not sure what I need to do to fix the issue above, only that there's something going on with my use of single quotes and double quotes.

Edit: This is the example file I'm using

//Creates the new browser and Logins in
console.log('Validation Complete');
var test = require('./js/Optimus.js');

test.smokeTest('####', '####', 'http://mydomain.com/myproject/');
  • 1
    Backwhack those HTTP slashes inside the s/// – thrig Apr 26 '16 at 16:51
  • What's '(.*?)' supposed to match ? '####' ? It'll never match that. – don_crissti Apr 26 '16 at 17:24
1

First of all:

  • The last double quote you used is change it to ".

Then:
The main issue is that you are using / for the s option of sed but your string also contains (un-quoted) /. The simplest solution is to change to # for the s delimiter, as this:

sed -i -e "s#test.smokeTest('(.*?)', '(.*?)', '(.*?)')#test.smokeTest(‘username’, ‘password’, 'http://localhost:8081/myproject')#g” test.js

I also believe you should solve this:

  • You are using and around username and password. Change them to '.

Edit for new file.

For the file you just added to your question, you need to escape the parenthesis and remove the ?:

sed -i -e "s#test.smokeTest('\(.*\)', '\(.*\)', '\(.*\)')#test.smokeTest('username', 'password', 'http://localhost:8081/myproject')#g" test.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.