使用sed命令

时间:2017-09-19 13:52:34

标签: linux sed samba

文件中的文字如下所示:

[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

它会对路径所在的文件中的任何位置进行更改。

任何人都可以帮我吗?

1 个答案:

答案 0 :(得分:0)

sed '/path[ ]*=[ ]*$/s#$#/data#'

在结尾前面有path =且有任意数量空格的行上,用替换字符串替换结束行$