【发布时间】:2015-03-03 01:58:21
【问题描述】:
基于:sed: Replace part of a line
我想修改我的sysctl.conf 文件。包含PermitTunnel something 的行必须更改为PermitTunnel point-to-point。
所以使用之前一位男士在帖子中所说的,我会使用:
sed -e 's/PermitTunnel.*$/PermitTunnel point-to-point/g'
包括在我的文件的行尾。
由于没有使用-n,我想我应该会以标准输出接收我的操作结果。然后我执行它并得到(注意我使用-2-而不是-to-只是为了看看我是否可以根据需要修改文件,因为在这种情况下文件已经有所需的行):
root@debian:/home/dit# sed -e 's/PermitTunnel.*$/PermitTunnel point-2-point/g'/etc/sysctl.conf
PermitTunnel point-2-point
但我会这样做:
root@debian:/home/dit# cat /etc/sysctl.conf | grep PermitTunnel
PermitTunnel point-to-point
如您所见,文件没有改变。我做错了什么?
感谢阅读
【问题讨论】:
-
与sed edit the file in place 完全一样。不投票关闭,因为它会自动关闭。