Sed replace not functioning as expected
Solution 1
First of all, A single quote may not occur between single quotes, even when preceded by a backslash.
, ref Bash Manual
Second, you may want to use some other char as separator instead of /
as you have /
in the replacement string.
So as a result:
sudo sed "s#listen = 127.0.0.1:9000#listen = '/var/run/php56-fpm.sock'#g" /etc/php-fpm.d/www.conf
don't use -i
yet, have a look at the print out to verify if it works as expected.
Solution 2
try using other chars rather than / for separation maybe?
sudo sed -i "s@listen = 127.0.0.1:9000@listen = '/var/run/php56-fpm.sock'@g" /etc/php-fpm.d/www.conf
OR
sudo sed -i "s/listen = 127.0.0.1:9000/listen = '\/var\/run\/php56-fpm.sock'/g" /etc/php-fpm.d/www.conf
The problem is that you are not escaping the /
as \/
but using @ as separator will fix your problem. You can use ANY separator in sed as soon as your are consistent.
And true from @David, use double quotes as per bash manual.
tip: all UX files need EOF in the last empty line
Related videos on Youtube
Adam Silver
Updated on September 18, 2022Comments
-
Adam Silver over 1 year
I want to replace
listen = 127.0.0.1:9000
bylisten = '/var/run/php56-fpm.sock'
sudo sed -i 's/listen = 127.0.0.1:9000/listen = \'/var/run/php56-fpm.sock\'/g' /etc/php-fpm.d/www.conf
Error:
bash: -c: line 63: unexpected EOF while looking for matching `'' bash: -c: line 64: syntax error: unexpected end of file
-
Adam Silver about 8 yearsboth are not working.
-
Kramer about 8 yearssorry, I corrected, from single to double quote enclosing, David is right :)
-
Jason about 8 yearsIndeed, a lot of people forget about being able to use a different separator character such as ':', which also holds true when doing search and replace in vim.