Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

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}'
share|improve this question
up vote 10 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


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.