0

I'm trying to use awk to parse an output generated by a java application, but it isn't working. It seems that the command after the pipe isn't able to get/see the data throwed by the java app.

I'm executing the following command (with the return generated by the command):

[root@localhost]# java -jar jmxclient.jar usr:pass host:port java.lang:type=Threading ThreadCount
06/11/2010 15:46:37 -0300 org.archive.jmx.Client ThreadCount: 103

What I need it's only the last part of the string. So I'm tryng to use awk (with pipe at the end of the line |awk -F ':' '{print $4}':

[root@localhost]# java -jar jmxclient.jar usr:pass host:port java.lang:type=Threading ThreadCount|awk -F ':' '{print $4}'

But the output isn't being parsed. It throws the entire string: 06/11/2010 15:46:37 -0300 org.archive.jmx.Client ThreadCount: 103

I also tryed to use |cut -f4 -d":" with the same result: the string isn't parsed.

So my question is, how do I parse the output in order to get just the number at the end of the string?

TIA,

Bob

Bob Rivers
  • 516
  • 5
  • 13

2 Answers2

5

Like Ignacio Vazquez-Abrams said, it's probably going to stderr. As well, there's an awk trick that will make your life easier: $NF, which is the last field. Thus, I would do something like this:

java -jar jmxclient.jar usr:pass host:port java.lang:type=Threading ThreadCount 2>&1 | awk -F: '{print $NF}'
Bill Weiss
  • 10,979
  • 3
  • 38
  • 66
3

The log is probably being output to stderr.

Instructions for bash

Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84
  • Thanks. That was the case. But simply using 2>$1 was generating an ambiguous redirect error. Using Bill Weiss awk trick solved it. – Bob Rivers Jun 11 '10 at 20:43
  • 1
    `2>$1` won't work, but `2>&1` will. I'm just adding on to that with a bit of Awk-fu. – Bill Weiss Jun 11 '10 at 21:48