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 個の空白文字に置き換えます。

おすすめ記事