James G. Sack (jim) 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.

I have a file that has many, many, many long lines, each with many sets
of data, each set being separated by many spaces, each instance of which
is ended by character 0x013, kinda like:
data   ^Mdata   ^Mdata   ^Mdata   ^Mdata   ^M
but the spaces before the ^M are about 77 in number (seems to be
consistent), and the data strings are longer, containing several
elements, each separated by either one, two, or three spaces.  If I can
match on any number of spaces ("[ ]*") which are immediately followed by
0x013 (^M) and replace each instance with a newline, I'll be set (almost
certainly).

As others have said, the ^M (0x0D, or CR "carriage return") may indicate
you have a DOS format file, with line endings  actually being a CR,LF
combination (0x0D, 0x0A).

  (You said 0x013, but I think you may have been confusing
   decimal with hex, since hex 0x0D = decimal 13.)


Oops.

Then again, that's why I wrote it different ways, just in case I was messing one up. I was certain about ^M, but that's a notation using two ASCII characters to represent the actual ASCII 13 character and I was afraid someone out there would think I was trying to match on the two characters, "^" and "M". I had ASCII in my head when I wrote the 0x013. But you are correct. I should have written 0x0D.

I did not know you could designate this character to sed by using CR. But \r worked. Chris wrote /r, which prompted me to try \r. That worked, so I didn't even try /r.


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

Reply via email to