I would like to parse the output of cdrecord/wodim using grep. cdrecord -v outputs lines like

Track 01:   49 of   75 MB written (fifo 100%) [buf 100%]  10.2x.

The problem is that cdrecord uses carriage returns (CR, \r) in order to show the progress in the same line.

I tried to append tr '\r' '\n' to the cdrecord call, which works generally, but the output won't show line by line. Instead, large chunks of text are parsed and displayed:

cdrecord -v ... | tr '\r' '\n' | grep -i written

Is this due to cdrecord, tr or grep? Is there any way to force flushing in order to get the output line by line?

Any help appreciated.

  • 2
    IIRC tr and grep both are buffered..you can try cdrecord -v ... | stdbuf -o0 tr '\r' '\n' | grep --line-buffered -i written
    – heemayl
    Feb 10, 2016 at 13:23
  • @heemayl: thank you very much! Works like a charm! However, the --line-buffered option of grep only works on grep's output, so I guess this is unnecessary.
    – mefiX
    Feb 10, 2016 at 13:48
  • Right.. Answer added..
    – heemayl
    Feb 10, 2016 at 13:51
  • Important here is that cdrecord calls fflush(stdout) to update a line. This is sufficient for all GUI implementations that parse the output in order to convert it into a growing bar window.
    – schily
    Feb 10, 2016 at 14:57

1 Answer 1


The output of tr is buffered. You can use stdbuf -o0 with tr to make it's STDOUT unbuffered:

cdrecord -v ... | stdbuf -o0 tr '\r' '\n' | grep -i written

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.