0

How can I make this regular expression work correctly. Is adding the line

LOGIN_SERVICE: '"https://dev-login-o365.grey.com/gp_loginservice/"',

in the file env.js I'm using the regular expresion:

sed -i '5i LOGIN_SERVICE: '"https://login.xxxx.com/server/"',' ./env.js

But is adding the value without the quotes and 3 spaces more to the left like this:

enter image description here

Joaquin
  • 2,013
  • 3
  • 14
  • 26
Chanafot
  • 736
  • 4
  • 22
  • 46

1 Answers1

2

Use different quoting:

sed -i "5i LOGIN_SERVICE: '\"https://login.xxxx.com/server/\"'," env.js

Or as the helpful comments below suggest, wrap sed command in single quote:

sed '5i LOGIN_SERVICE: '\''"https://login.xxxx.com/server/"'\'',' env.js
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    Alternatively, `'5i LOGIN_SERVICE: '\''"https://login.xxxx.com/server/"'\'','` - this is useful for programmatic quoting, since it's just `s.replace("'", "'\\''")` – o11c Jul 26 '18 at 16:55
  • 1
    Don't use double quotes around scripts as then you're exposing the whole text to the shell for interpretation before sed even sees it so you'll get a surprise if/when your text contains characters the shell will act on (e.g. $). Just do `sed -i '5i LOGIN_SERVICE: '\''"https://login.xxxx.com/server/"'\'',' ./env.js` instead like @o11c suggested. – Ed Morton Jul 27 '18 at 13:06
  • Thanks, That's fair point Ed and @o11c – anubhava Jul 27 '18 at 13:44