The suggested answer using "sed -r" relies upon GNU sed, which makes it not really portable. It is possible to do the same functionality with POSIX sed, but differently: POSIX does not provide for passing a whole script in a command option as shown here. That means that the (POSIX) way to implement a loop would be in a separate file, passed to sed using the "-f" option. Likewise, the hexadecimal constants are not portable. After making these changes, a functionally equivalent script can be used on the BSDs and Unix systems.
The suggested answer also does not cover some of the uses of carriage returns which are fairly common (for instance in yum output), nor does it filter out "most" ANSI sequences (since it focuses on the SGR "m" final character). Finally, it refers to
escape _ text _
as an xterm extension. But no such extension is provided by xterm, because the two characters "escape" and "_" begin an Application Program Command sequence (and xterm implements none).
The resulting sed-script looks like this ("^[" is the escape character):
s/^[[[][<=>?]\{0,1\}[;0-9]*[@-~]//g
s/^[[]][^^[]*^G//g
s/^[[]][^^[]*^[\\//g
:loop
s/[^^H]^H\(.\)/\1/g
t loop
s/^M^M*$//g
s/^.*^M//g
s/^[[^[]//g
A more complete script, named "script2log" can be found here. There are, however, things (such as CSI K) which are not suited to a sed script.