我需要/etc/lightdm/lightdm.conf
使用sed
内部特定部分进行编辑,取消注释并设置值。
此部分是[Seat:*]
且行是#autologin-user=
我预计会有这样的变化:
之前:
[LightDM]
.
.
.
[Seat:*]
.
.
.
#autologin-user=
.
.
.
后:
[LightDM]
.
.
.
[Seat:*]
.
.
.
autologin-user=pi
.
.
.
我试过这个命令:
sed -i.bak '/^\[Seat:*]/{s/#autologin-user/autologin-user=pi/}' /etc/lightdm/lightdm.conf
但没有成功。
PS:出现的次数比较多#autologin-user
,所以选择section[Seat:*]
非常重要。
答案1
尝试使用这个,给定一个改变的输入文件示例:
[LightDM]
[Seat:*]
#autologin-user=
[Foo:*]
#autologin-user=
[Bar:*]
#autologin-user=
命令:
$ sed '/^\[Seat:\*\]$/,/\[/s/^#autologin-user=$/autologin-user=pi/' foo.txt
[LightDM]
[Seat:*]
autologin-user=pi
[Foo:*]
#autologin-user=
[Bar:*]
#autologin-user=