Reputation: 2232
I have a java program that takes time to execute and I have to make 10 runs of it and I am interested in only last 5 lines of the output, the actual output runs in hundreds of lines. Since I want to average the output I want tail -5
for run into a file. Also one of the parameters (--random)
in my arguments keep changing in each run.
I am doing the following:
for i in {1..10} ; do cat output| tail -5 | java -cp src.Tagger.java --random $1; done
Sorry I am really bad at bash.
Upvotes: 1
Views: 1486
Reputation: 25524
You want the output of your java program to go to output first, then you need to tail the file. It looks like you are currently feeding output into your java program as input. I don't think that is what you want. Try this instead:
for i in {1..10}
do
java -cp src.Tagger.java --random $1 > output;
tail -5 output;
done
I also have my doubts that you have the java command correct. You shouldn't specify .java for the file name when running the java file. It needs to run from the compiled .class file and the java command assumes .class, so it isn't needed on the command line. You also are using -cp (classpath) but don't appear to be giving it an argument. I'd expect the java command to be more like:
java -cp classesdir com.mydomain.myapp.Tagger
Upvotes: 1
Reputation: 123490
You should make sure you can execute your java program at all first. You can't execute a .java file directly, it has to be compiled.
If you have the file src/Tagger.java
, you can try to compile it with
javac -cp src src/Tagger.java
but if it requires other libraries or build systems, it might be completely different. If you downloaded this app, see the project documentation.
This should silently produce a src/Tagger.class
. Once you have this, you can try to run it with
java -cp src Tagger --random 1234
though again, if it has dependencies on libraries, it'll be different.
If that works, you can finally start trying to run it in a loop:
for i in {1..10}
do
cat output| tail -5 | java -cp src Tagger --random 1234
done
Upvotes: 1