Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extract second word from a file in yum repository file using command line or bash

I wanted to extract a paticular file path from a text file (yum repository file) The file contents looks like this

[rhel-8-for-x86_64-baseos-rpms]
name = Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)
baseurl = https://myhost.com
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
sslverify = 1
sslclientkey = /etc/pki/entitlement/60472949067-key.pem
sslclientcert = /etc/pki/entitlement/604712349067.pem
metadata_expire = 1
enabled_metadata = 1

[rhel-8-for-x86_64-appstream-rpms]
name = Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)
baseurl = https://myhost.com
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
sslverify = 1
sslclientkey = /etc/pki/entitlement/6047297349067-key.pem
sslclientcert = /etc/pki/entitlement/6047297349067.pem
metadata_expire = 1
enabled_metadata = 1

My requirement is to extract sslclinetkey path of both rhel-8-for-x86_64-appstream-rpm and rhel-8-for-x86_64-baseos-rpm through the command line or script

Any help would be appreciated

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

UPDATE

I tried this way, but I am getting multiple entries

cat /etc/yum.repos.d/redhat.repo  | grep sslclientkey | awk '{print $3}'
/etc/pki/entitlement/2627848977587647846-key.pem
/etc/pki/entitlement/7675461792121821585-key.pem
/etc/pki/entitlement/3236342435348109549-key.pem
/etc/pki/entitlement/60472974412349067-key.pem
/etc/pki/entitlement/3236342435348109549-key.pem
/etc/pki/entitlement/60472974412349067-key.pem

But I only need of rhel-8-for-x86_64-appstream-rpm and rhel-8-for-x86_64-baseos-rpm

>Solution :

awk -F' = ' '/sslclientcert/{print $2}' file 
# or 
awk '/sslclientcert/{print $3}' file 

/etc/pki/entitlement/604712349067.pem
/etc/pki/entitlement/6047297349067.pem

awk -F' = ' '/\[.*\]/ {printf "%s ", $1} /sslclientcert/{print $2}' file 
[rhel-8-for-x86_64-baseos-rpms] /etc/pki/entitlement/604712349067.pem
[rhel-8-for-x86_64-appstream-rpms] /etc/pki/entitlement/6047297349067.pem
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading