如何从repo文件中仅提取已启用的存储库?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何从repo文件中仅提取已启用的存储库?相关的知识,希望对你有一定的参考价值。

我试图使用awk或grep从下面的文件中仅提取启用的repos。我知道有这样的原生工具,如“yum repolist enabled”,但我仍然想用grep awk甚至sed这样做。

输出结果应该是[]中的字符串。例如:“red-hat-enterprise-linux-scalable-file-system-for-rhel-6-entitlement-rpms”,这是此文件中唯一启用的repo。

# cat /etc/yum.repos.d/redhat.repo
[red-hat-enterprise-linux-scalable-file-system-for-rhel-6-entitlement-rpms]
name = Red Hat Enterprise Linux Scalable File System (for RHEL 6 Entitlement) (RPMs)
baseurl = https://cdn.redhat.com/content/dist/rhel/entitlement-6/releases/$releasever/$basearch/scalablefilesystem/os
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
sslverify = 1
sslcacert = /etc/rhsm/ca/redhat-uep.pem
sslclientkey = /etc/pki/entitlement/key.pem
sslclientcert = /etc/pki/entitlement/11300387955690106.pem

[red-hat-enterprise-linux-scalable-file-system-for-rhel-6-entitlement-source-rpms]
name = Red Hat Enterprise Linux Scalable File System (for RHEL 6 Entitlement) (Source RPMs)
baseurl = https://cdn.redhat.com/content/dist/rhel/entitlement-6/releases/$releasever/$basearch/scalablefilesystem/source/SRPMS
enabled = 0
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
sslverify = 1
sslcacert = /etc/rhsm/ca/redhat-uep.pem
sslclientkey = /etc/pki/entitlement/key.pem
sslclientcert = /etc/pki/entitlement/11300387955690106.pem

[red-hat-enterprise-linux-scalable-file-system-for-rhel-6-entitlement-debug-rpms]
name = Red Hat Enterprise Linux Scalable File System (for RHEL 6 Entitlement) (Debug RPMs)
baseurl = https://cdn.redhat.com/content/dist/rhel/entitlement-6/releases/$releasever/$basearch/scalablefilesystem/debug
enabled = 0
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
sslverify = 1
sslcacert = /etc/rhsm/ca/redhat-uep.pem
sslclientkey = /etc/pki/entitlement/key.pem
sslclientcert = /etc/pki/entitlement/11300387955690106.pem
答案
awk -v RS= -F '[][]' '/enabled = 1/{print $2}' file
另一答案

尝试

awk '/[/' infile | sed 's/[][]//g'

我发现方括号部分很棘手,here是我得到它的地方。

以上是关于如何从repo文件中仅提取已启用的存储库?的主要内容,如果未能解决你的问题,请参考以下文章

如何从 SubRip .srt 文件中仅提取文本(剥离时间码)?

如何从 XML 中仅提取标签名称(而不是值),最终使用 XPath

在 Git Commit 中仅克隆新上传的文件

如何更改 gradle 插件存储库?

删除 git repo 中的文件夹? [复制]

如何从日期时间对象中仅提取月份和日期?