yesterday I asked the question how save the console output in a file (see redirect only last line of STDOUT to a file). Now I iterate over files, compile them. Here is my command:
for REPORT in Test_Basic_*.scala; do
scalac -Xplugin:divbyzero.jar $REPORT | awk 'END{print $REPORT} END{print}' >> output.txt
done
I want to save the last output of the compilation and the name of the file. In the example above only $REPORT will be saved but I want to refere to the name of the iteration variable.
For example I have the file Test_Condition.scala and run the command above:
for REPORT in Test_Basic_*.scala; do
scalac -Xplugin:divbyzero.jar $REPORT | awk 'END{print $REPORT} END{print}' >> output.txt;
done
Then scalac -Xplugin:divbyzero.jar $REPORT produce the following output:
You have overwritten the standard meaning
Literal:()
rhs type: Int(1)
Constant Type: Constant(1)
We have a literal constant
List(localhost.Low)
Constant Type: Constant(1)
Literal:1
rhs type: Int(2)
Constant Type: Constant(2)
We have a literal constant
List(localhost.High)
Constant Type: Constant(2)
Literal:2
rhs type: Boolean(true)
Constant Type: Constant(true)
We have a literal constant
List(localhost.High)
Constant Type: Constant(true)
Literal:true
LEVEL: H
LEVEL: H
okay
LEVEL: H
okay
false
symboltable: Map(a -> 219 | Int | object TestIfConditionWithElseAccept2 | normalTermination | L, c -> 221 | Boolean | object TestIfConditionWithElseAccept2 | normalTermination | H, b -> 220 | Int | object TestIfConditionWithElseAccept2 | normalTermination | H)
pc: Set(L, H)
Now I want to save in output.txt Test_Condition.scala (name of the file) and pc: Set(L, H) (so the last line of the compilation output). With my command above I only save $REPORT pc: Set(L, H).
If this explanation is to complicated just tell me. Thanks for your great support.
Matthias
If I interpret your question correctly, you simply want a way to execute a command on a bunch of files and then store both the name of the file and the last line of the output of the command. This should work:
: > output # clear out the output file for file in Test_Basic_*.scala; do printf "$file: " >> output scalac ... | awk 'END { print }' >> output done