文件中的文字如下所示:
[homes]
comment = Home Directories
path =
browseable =
writable = yes
valid users = %S
valid users = MYDOMAIN\%S
[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
guest ok = no
writable = no
printable = yes
我希望输出为:
[homes]
comment = Home Directories
path = /data
browseable = yes
writable = yes
valid users = %S
valid users = MYDOMAIN\%S
[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
guest ok = no
writable = no
printable = yes
我正在使用此命令:
sed -i "\#path# s#.*#& /data#" file
它会对路径所在的文件中的任何位置进行更改。
任何人都可以帮我吗?
答案 0 :(得分:0)
sed '/path[ ]*=[ ]*$/s#$#/data#'
在结尾前面有path =
且有任意数量空格的行上,用替换字符串替换结束行$
。