Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to use sed to pull out the version number from the command:

svnversion --version

Which gives output like:

svnversion, version 1.6.2 (r37639)
   compiled May 10 2009, 12:41:21

Copyright (C) 2000-2009 CollabNet.
Subversion is open source software, see
This product includes software developed by CollabNet (http://www.Collab.Net/).

And after processing with sed, I'd like just:


So far, I have this monstrosity (due to my ignorance):

svnversion --version | sed s/[\wa-zA-Z//\(\):,]*//g | sed 's/[ ]//' | sed 's/[ ]//' | sed 's/[ ][0-9 ./n/-]*//'

I'm sure there is a simple elegant solution that an expert can provide easily.

share|improve this question
up vote 5 down vote accepted

I know this isn't using sed, but based upon your output this is easier.

svnversion --version | head -1 | awk '{print $3}'

If you have perl available...

svnversion --version | perl -lne 'print $1 if /version (\d+.\d+.\d+)/'
share|improve this answer
Yep: UNIX command lines are all about using the right tool for the job. – Shannon Nelson Dec 8 '09 at 3:37

Try this:

svnversion --version | sed -n '/version/ s/.*version \([0-9]\+\.[0-9]\+\.[0-9]\+\) .*/\1/p'

It says:

  • -n --- Don't automatically print output.
  • /version/ --- On lines that include the string "version",
  • s/ - substitute for what's
  • .*version and .* --- between [a sequence of zero or more of any character, the string "version", a space] and [a space, a sequence of zero or more of any character],
  • \(...\) --- capturing
  • [0-9]\+ --- a sequence of one or more digits
  • \. --- followed by a literal period
  • then more digits and periods,
  • /\1/ --- what was captured in the first (and only, in this case) set of parentheses
  • p --- and explicitly print it.

Because automatic printing is suppressed and only the line that includes "version" is selected, the other lines are ignored.

share|improve this answer

One more way to do it w/o sed: svnversion --version | head -1 | cut -d" " -f3

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.