Output of `java -version` not matched by grep or awk
5,948
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}'
Related videos on Youtube
Author by
yael
Updated on September 18, 2022Comments
-
yael almost 2 years
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
orawk
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"