Sorry if this is not the correct place for this question, but I'm certain someone on here will know how to do this.
Calling this in a shell:
g++ --version
outputs the following:
g++ (SUSE Linux) 4.4.1 [gcc-4_4-branch revision 150839]
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Please can someone help with the sed and/or other shell commands which will be able to parse out the g++ version number. ie, I'm looking for the output from sed to be the following:
4.4.1
At the moment I'm using this command:
g++ --version | sed -e 's/[a-Z+()$/[,;]*//g'
and getting the following:
4.4.1 -4_4- 150839]
2009 .
.
.
which I guess is kinda half-way there... but at this point my limited knowledge of sed fails miserably!
Would I be correct in saying that that would fail if the version changed to anything other than x.x.x form? (ie: if the version was 5.0)
I don't know what the standardised form of gcc's version is... of course it could be that the version would be 5.0.0, but I don't know.
I imagine that a more robust way of parsing out the version would be to strip out alpha characters, leaving [whitespace]*[version][whitespace]*[something else]*
That leaves us with just finding a way to get rid of the leading whitespace, and then keep everything before the first occurrence of whitespace.
Maybe I'm totally over-engineering it, or barking up the wrong tree, or just barking mad?!
Usually software developers are consistent with version scheme.
When you are looking for a part of some text, you usually want to find the part itself rather than removing everything else.
Anyway, if you remove everything leaving only numbers and dots you will likely end up with some other characters you don't want ( for example the copyright year and periods )