私のファイルの最後の数行は次のとおりです/usr/share/glib-2.0/schemas/org.gnome.Vino.gschema.xml
。
<schemalist>
<schema>
<!-- some other tags -->
<key name='notify-on-connect' type='b'>
<summary>Notify on connect</summary>
<description>
If true, show a notification when a user connects to the system.
</description>
<default>true</default>
</key>
<key name='enabled' type='b'>
<summary>Enable remote access to the desktop</summary>
<description>
If true, allows remote access to the desktop via the RFB
protocol. Users on remote machines may then connect to the
desktop using a VNC viewer.
</description>
<default>false</default>
</key>
</schema>
</schemalist>
この段落が必要な場合grep
:
<key name='enabled' type='b'>
<summary>Enable remote access to the desktop</summary>
<description>
If true, allows remote access to the desktop via the RFB
protocol. Users on remote machines may then connect to the
desktop using a VNC viewer.
</description>
<default>false</default>
</key>
grep
これを達成するには、このコマンドをどのように使用する必要がありますか?
ベストアンサー1
提供した例は有効なXMLファイルなので、xq
XMLパーサーツールを使用してファイルを処理します。yq
インストールパッケージ。
xq -x --xml-root key '
.schemalist.schema.key[] | select(."@name" == "enabled")
' infile.xml
「key」タグの「@name」属性が「enabled」と同じ場合、「key」タグが選択されます。
からxq -h
:
--xml-出力、-x
jq JSON出力を再びXMLにトランスコードしてエクスポートします。
--xml-rootXML_ROOT
XMLに再トランスコードするときは、出力をこの名前の要素にラップします。