I am trying to add a string to the end of a line using sed and regex.
我正在尝试使用sed和regex向行尾添加一个字符串。
I have the following string:
我有以下的字符串:
disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
and im trying to add to the end of it the string:
我试着在它的末尾加上一串:
exec,system,shell_exec,passthru,
My attempt is as follows:
我的尝试如下:
sed -ie 's/disable_functions = .*[a-zA-z,]$/disable_functions = $1exec,system,shell_exec,passthru,/gI' /etc/php5/apache2/php.ini
It seems to just add $1 to the string disable_functions = $1exec,system,shell_exec,passthru,
它似乎只给string disable_function = $1exec,system,shell_exec,passthru增加$1,
Where am I going wrong?
我哪里出错了?
2 个解决方案
#1
2
Try that :
试一试:
sed '/^disable_functions/s/$/exec,system,shell_exec,passthru,/' /etc/php5/apache2/php.ini
If the output seems OK, then add -i
switch to modify the file.
如果输出看起来没问题,那么添加-i开关来修改文件。
$
here, mean end of line.
这里是指线的末端。
#2
1
Your original command is missing the capture group which sets the value of \1
(not $1
):
您的原始命令丢失了设置\1值的捕获组(不是$1):
sed -ie 's/disable_functions = \(.*[a-zA-z,])\$/disable_functions = \1exec,system,shell_exec,passthru,/gI' /etc/php5/apache2/php.ini
But as sputnick
points out, you simply need to find the appropriate line and append the desired text; there's no need to match the old values and reinsert them.
但是正如sputnick所指出的,您只需要找到适当的行并附加所需的文本;不需要匹配旧值并重新插入它们。
#1
2
Try that :
试一试:
sed '/^disable_functions/s/$/exec,system,shell_exec,passthru,/' /etc/php5/apache2/php.ini
If the output seems OK, then add -i
switch to modify the file.
如果输出看起来没问题,那么添加-i开关来修改文件。
$
here, mean end of line.
这里是指线的末端。
#2
1
Your original command is missing the capture group which sets the value of \1
(not $1
):
您的原始命令丢失了设置\1值的捕获组(不是$1):
sed -ie 's/disable_functions = \(.*[a-zA-z,])\$/disable_functions = \1exec,system,shell_exec,passthru,/gI' /etc/php5/apache2/php.ini
But as sputnick
points out, you simply need to find the appropriate line and append the desired text; there's no need to match the old values and reinsert them.
但是正如sputnick所指出的,您只需要找到适当的行并附加所需的文本;不需要匹配旧值并重新插入它们。