使用 sed 命令插入行

使用 sed 命令插入行

文件中的文本如下所示:

 [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

如果您只想更改缩进,可以这样做:

sed 's/ \{12\}/        /' file

它需要 12 个连续空格字符 ( \{12\}) 并用 8 个空格替换它们。

相关内容