/var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla
構成ファイル( )の変更をスクリプトで作成しようとしますが、その内容は次のとおりです。
[Update already installed software]
Identity=unix-group:admin;unix-group:sudo
Action=org.debian.apt.upgrade-packages
ResultActive=yes
[Printer administration]
Identity=unix-group:lpadmin;unix-group:admin;unix-group:sudo
Action=org.opensuse.cupspkhelper.mechanism.*
ResultActive=yes
[Disable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=no
ResultActive=yes
で始まるすべてのブロックを設定しようとしています[Disable hibernate
。 sedグループとregexグループを使用して、次のことを考えました。
sed -i 's/\(Disable hibernate.*\n.*\n.*\nResultActive\=\)no/\1yes/' /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla
ただし、このようにしてもファイルは変更されません。 ~によると正規表現、正規表現は一致しますが、確認します。sed.js.org、sedは何も変更しません。
sed
休止状態設定ブロックの対応する行を変更するコマンドをどのように変更しますか?
編集する:sed
改行文字のあるグループがまったく機能しないようです。
ベストアンサー1
Sedは基本的に行ベースです。複数行の一致を実行するには、パターン空間に明示的に行を追加する必要があります(N
例:コマンドを使用)。
代わりに、まだ行ベースですが、関心のある行を前方に読み込む同様の操作を実行できます。
$ sed '/^\[Disable hibernate/{n;n;n;/^ResultActive/s/=no/=yes/;}' file.pkla
[Update already installed software]
Identity=unix-group:admin;unix-group:sudo
Action=org.debian.apt.upgrade-packages
ResultActive=yes
[Printer administration]
Identity=unix-group:lpadmin;unix-group:admin;unix-group:sudo
Action=org.opensuse.cupspkhelper.mechanism.*
ResultActive=yes
[Disable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes
元のバージョンと同様に、これはブロックの行順序を信頼できる場合にのみ機能します。