markw wrote:
Ralph Shumaker wrote:
I want to do this:
cat myFile | sed -e "s/[ ]*CTRL-M/\n/g" > myFileCleaned
where Ctrl-M is character 0x013 and \n is a newline.

Is this a dos file? Are the ^M's at the end of the line? There's a utility that is probably already on your machine called dos2unix.

Mark




DOS???  What caused you to make *that* leap?

No, this is not a DOS file. And no, the ^M's are not at the end of the line. Was this not clear with the example:
data   ^Mdata   ^Mdata   ^M
as opposed to:
data   ^M^Jdata   ^M^Jdata   ^M^J

And to Chris, no, the ^M is not followed by ^J (or, using your terms, /r/n).

But thank you Chris. I just barely remembered the \n being a newline. \r may be what I'm looking for:
cat myFile | sed -e "s/[ ]*\r/\n/g" > myFileCleaned

(Maybe I don't need the [ and ] in the formula, but I got tired of trying to keep it straight whether I need them or not. If in doubt, I throw them in, which BTW is a decent way to keep grep from matching itself in "ps -Helf | grep -i [f]irefox".)

Yep, the \r was the magic bean I wanted. Thanks. That is *far* more readable!

BTW, the data I wanted to clean up is the output of:
mplayer dvd://1 >myFile 2>myFile

I was getting a *lot* of errors on stdout which were flying by far too quickly. I was hoping that this would basically give me a capture of what was flying by on my screen. It doesn't drop into the file the same way as it outputs to the screen, but at least it's all there (I think). Is there even a way to dump output on a gnome-terminal into a file exactly as it appears on the screen (specifically, with stderr interspersed the same)?

The errors that I'm getting there merit their own thread.

Each time mplayer refreshes its status on the screen, it prints the new status line, followed by about 77 spaces and a simple carriage return (no newline). Even without errors, when this dumps to the file, you get a big mess of *extremely* long lines of mplayer status lines. It was a pain to navigate through it while looking for anything interesting. sed to the rescue. It shrank a 16.6M file down to a 8.6M file and aligned things quite nicely. Holding PageDown allowed me to quickly find anomalies (such as infrequent occurrences of "[AO_ALSA] Trying to reset soundcard.").




--
Ralph

--------------------
Tree dating involves many assumptions, but the fact that the oldest known dates are near 4,500 years confirms the date of the global Flood described in Genesis. Apart from the Flood, there is no reason why trees older than 4,500 years should not be alive today.


--
KPLUG-List@kernel-panic.org
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to