tags:

views:

231

answers:

2

I am trying to run this dreadfully simple command in Bash

java -cp nasa-top-secret.jar gov.nasa.RocketToMoon | grep -v codehaus

but grep is not working (it does not filter out my string). How can I filter my java output using grep?

+12  A: 

The output could be on STDERR, Try this instead:

java -cp nasa-top-secret.jar gov.nasa.RocketToMoon 2>&1 | grep -v codehaus
ar
Thanks ar! That worked perfectly.
Yar
+3  A: 

possible scenario

  1. you actually have all the lines with "codehaus", so grep -v gives you nothing. I assume you know what -v stands for.
  2. your java program did not print anything to stdout. check your source and make sure your program spits out to stdout. Otherwise, check if its stderr that your program is spitting out.

possible troubleshooting step:

  1. remove the pipe to grep, run only the java program and make sure your program has output.
  2. put 2>&1 at the end of the command and try again with grep
ghostdog74