I’m on RedHat, I need to get the value in the Release field.
Take “wget” for an example.
Here’s the output I’m expected to get
WGET: 1.4.el6
Here’s the output from rpm -qi wget
[luke@machine ~]# rpm -qi wget
Name : wget Relocations: (not relocatable)
Version : 1.12 Vendor: Red Hat, Inc.
Release : 1.4.el6 Build Date: Mon May 10 14:56:18 2010
Install Date: Wed Oct 3 16:48:58 2012 Build Host: x86-012.build.bos.redhat.com
Group : Applications/Internet Source RPM: wget-1.12-1.4.el6.src.rpm
Size : 1877597 License: GPLv3+ and GFDL
Signature : RSA/8, Mon Aug 16 21:21:35 2010, Key ID 199e2f91fd431d51
Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
URL : http://wget.sunsite.dk/
Summary : A utility for retrieving files using the HTTP or FTP protocols
How can I write a script to extract the “1.4.el6” from the Release field.
I currently have
#!/bin/bash
RELwg= rpm -qi wget
# Do string manipulation of $RELwg here
wg="WGET: "
echo $wg$RELwg
But here’s the output I get;
Release : 1.4.el6 Build Date: Mon May 10 14:56:18 2010
WGET:
I know I have to do some string extraction, to get the number.
- Get the index of the 1, seems to always be constant at 15
- Get the index of the B in Build Date
- Get the sub string inbetween 15 and whatever B is
Removing the space between “RELwg= rpm -qi wget” in my current script, I just get an error saying that
./GetRPMVersions.sh: line 12: -qi: command not found
Mainly my current predicament is to addign the ouput of rpm -qi wget | grep Release to a variable.
Any input on the string manipulation is welcome.
something like