Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interpret ASCII command codes in a stream before saving to a file?

Tags:

linux

bash

I'm saving standard output stream to a file:

mvn test > output.txt

Before saving to a file I want to properly process ASCII command codes (especially 0x0D and 0x08) in order to make file more readable.

For example, in line 1\rline 2\n the \r should move the position to the start of the same line, so that overwriting from there results in line 2\n being saved. Similarly barbar\rfoo\n should end as foobar\n.

Do such tools exist in Linux or do I have to write something from scratch?

like image 317
yegor256 Avatar asked Jan 27 '26 11:01

yegor256


1 Answers

pipe your output through col -b. It doesn't understand all possible control characters and escape sequences, but at least it knows carriage return and backspace. It outputs what would be visible at the end if its input had been printed to a terminal. (An infinitely tall terminal with destructive backspace)


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!