Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

On my Linux machine, it isn't clear to me why if I do the following then I don't get only the version string ("1.5.0_32").

# java -version | grep version | awk '{print $NF}'
java version "1.5.0_32"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_32-b05)
Java HotSpot(TM) Server VM (build 1.5.0_32-b05, mixed mode)

Why don't grep or awk work?

Just to show that grep and awk work on other example

# echo ' java version "1.5.0_32" ' | grep version  | awk '{print $NF}'
"1.5.0_32"
share|improve this question

1 Answer 1

up vote 9 down vote accepted

Try like this:

java -version 2>&1 | grep version  | awk '{print $NF}'

Looks like the output is going to stderr.

Also, grep is not needed:

java -version 2>&1 | awk '/version/{print $NF}'
share|improve this answer
    
Plus one for the "grep not needed" :) –  tink Apr 18 '13 at 0:50

Your Answer

 
discard

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.