I\'m compiling Scala code and write the output console output in file. I only want to save the last line of the STDOUT in a file. Here is the command:
scalac
In Bash and other shells that support process substitution:
command | tee >(tail -n 1 > outputfile)
will send the complete output to stdout and the last line of the output to the file. You can do it like this to append the last line to the file instead of overwriting it:
command | tee >(tail -n 1 >> outputfile)