I've written a Java-console application that repeatedly prints its status to the console using carriage-returns (\r) at the end rather than line-feeds (\n) to keep the output on one screen. I also want to pipe that output to a file, like
java -jar my-jar.jar | tee /tmp/my-jar.log
However, it doesn't make sense to write everything to that file, just what's visible at the end of the application. In other words I don't need all the "lines" ending with \r there.
Example: I code
System.out.print("hello\r") Thread.sleep(2000); System.out.println("world")
"hello" appears on the screen and after two seconds it's replaced by "world". Therefore, after the program ends the user only sees "world" on the screen. Fine, that's correct.
However, if I tee that to a file it holds "hello\rworld\n", but I only want it to contain "world\n".
How do I do that on the command line rather than coding that in Java (which is why the question is here and not on SO)?