1

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?

2 Answers 2

3

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...

Sign up to request clarification or add additional context in comments.

1 Comment

I don't want name...I want the version part which is 1.1.0-1112
1

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:

  • starting from the beginning of the String
  • match as many non-numbers as there are
  • then the very next character is a -

And it replaces everything that matched with a blank, essentially removing it. This should leave everything after that which is the version string.

3 Comments

This seems to be working...Can you explain what it does & how it extracts version?
Why is - needed? Can I just use sed -e 's/^[^0-9]*//g' I simply want all the characters after "my-scheduler-"
@Mike I guess it's not needed, I had it in there when I was trying a different regex. As for -e: unixhelp.ed.ac.uk/CGI/man-cgi?sed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.