shell - Escape UNIX character -


this should easy can't out of it:

i need replace piece of text in .php file using unix command-line.

using: sudo sed -i '' 's/string/replacement/g' /file.php (the quotes after -i needed because runs on mac os x)

the string: ['password'] = ""; needs replaced by: ['password'] = "$pass"; $pass variable, gets filled in.

i got like:

sudo sed -i '' 's/[\'password\'] = ""\;/[\'password\'] = "$pass"\;/g' /file.php

but i'm new unix don't know escape...

what should changed? thanks!

if want expand variable in sed, have use double quote,

sed -i... "s/.../.../g" file 

that is, don't have escape single quotes, use group reference save typing. try:

sudo sed -i '' "s/\(\['password'\] = \"\)\(\";\)/\1$pass\2/g" /file.php 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -