0

How do I convert carriage returns from a text file to the way they are displayed in console?

So for example, if a program prints the following lines to a console:

start\n
progress  01%\r
progress  22%\r
progress  54%\r
progress 100%\n
completed

after a time the output in the console will look like this:

start
progress 100%\n
completed

but if I pipe the output to a file it will contain all the intermediate progress reports.

Preferably some solution that can be applied to large log files >100 MB.

7
  • There is a program called "sed" which does search and replace (among other things), but won't find new line characters 'cos it works line by line. However, there is a programming language called perl that can also act as a command line program too, and it can do search and replace, so you could get it to delete \r characters. Some perl one liners mentioned in the accepted answer here superuser.com/questions/416419/…
    – barlop
    Commented Apr 12, 2017 at 11:36
  • I'm pretty sure simple delete won't work because it will leave the intermediate strings progress 22% that would be overwritten otherwise because of the \r without \n. The below col answer already solved my issue but I couldn't yet (2 day timeout) mark it as the answer.
    – Jaakko
    Commented Apr 12, 2017 at 11:43
  • The words in your question could be better 'cos while your example shows some strings of text / lines, have been deleted, your words don't mention anything about deleting any lines.
    – barlop
    Commented Apr 12, 2017 at 12:10
  • If your subject was Remove lines with carriage returns from file, would that be a good description of what your goal was?
    – barlop
    Commented Apr 12, 2017 at 12:11
  • That's a different thing, because if first print is 1234\r followed with 321\n the end result in the console would be 3214\n. If you remove lines with carriage returns, the result would be 321\n.
    – Jaakko
    Commented Apr 12, 2017 at 12:35

1 Answer 1

1

Tool called col seems to do the trick

col -bp <filename.log > fileout.log

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .