I am writing a little program that packages configuration files as rpm, and it puts a series of %triggers to handle installation/upgrade of the packages that bring a copy/version of the same file.
I am stuck trying to format yum provides output. The default output is:
# yum provides */named.conf -q 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.i686 : A chroot runtime environment for the ISC BIND DNS server, named(8) Repo : base Matched from: Filename : /var/named/chroot/etc/named.conf sblim-cmpi-dns-test-1.0-1.el6.i686 : SBLIM WBEM-SMT Dns - Testcase Files Repo : base Matched from: Filename : /usr/share/sblim-testsuite/named.conf But i need only the package name. Using cut does not seem like a good idea. The delimiter would be - but there are several packages with a - in the middle of the package name.
Ideally I'd need the output to be formattable like for rpm queries:
rpm -qa --queryformat "%{NAME}\n" make rubygem-multi_json attr ncurses-base rubygem-rack-test strace rubygem-polyglot gpg-pubkey rubygem-journey tzdata ... 12 Answers
You will be happier if you ditch yum in favor of the repoquery command from the yum-utils package. With this, you just run:
$ repoquery --whatprovides '*/named.conf' --qf '%{NAME}' Which, on my system, returns:
bind sblim-cmpi-dns-test bind bind-chroot rubygem-openshift-origin-dns-bind system-config-bind logwatch bind-chroot 1I have devised an ugly solution for this problem using various yum commands, sed, grep and cut:
PKLIST=`yum provides -q */$FILE | grep -v 'Repo\|Matched\|Filename' | sed "s/32://g" | cut -d':' -f1 | sed "s/ //g" | grep -e '^$' -v` array=($PKLIST) arr2=() for i in "${array[@]}" do x=`yum info -C $i | grep "Name :" | sed "s/Name : //g"` arr2+=($x) done Then I removed duplicates from the array
arr3=$(echo "${arr2[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ') With my current bash knowledge it is the best I could do.