Reputation: 7914
I've a progam installed in my linux box called my-scheduler-1.1.0-1112
When I do rpm -qa | grep my, it lists as shown below:
my-scheduler-1.1.0-1112
I want a command which will extract 1.1.0-1112 which is version part in my shell script.
what would be the command to extract it in shell script?
Upvotes: 1
Views: 326
Reputation: 63892
For this question you can try the --queryformat parameter for rpm.
like:
rpm -qa --queryformat '%{NAME}' | grep my
should print
my-scheduler
without the version string... What is much better as mugling it with sed or like. Because you can get something like package-1.0.3-rc2
or soo..
For version-release: use:
--queryformat "%{VERSION}-%{RELEASE}"
and maybe will be useful read http://www.rpm.org/max-rpm/ch-queryformat-tags.html - here is many useful query format tags, so you can directly can get what you want and in what format you want, without scripting...
Upvotes: 3
Reputation: 143846
Not sure what other version strings you may encounter, but you can try:
sed -e 's/^[^0-9]*-//g'
This is a sed
replace. It's matching the regular expression ^[^0-9]*-
, which is:
-
And it replaces everything that matched with a blank, essentially removing it. This should leave everything after that which is the version string.
Upvotes: 1