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.
tr
andgrep
both are buffered..you can trycdrecord -v ... | stdbuf -o0 tr '\r' '\n' | grep --line-buffered -i written
--line-buffered
option of grep only works on grep's output, so I guess this is unnecessary.