Carriage return and line feed (Re: [Techtalk] get rid of "^M" in a file)

MMP - Barb Fox mmp_fox at bellsouth.net
Sat Jun 18 02:45:13 EST 2005


You're right, all you have to do is translate that CR into a LF:

cat macfile.txt | tr '\r' '\n' > cleanfile.txt

  OR use the ascii characters ('\015' for carriage return and LF I think is 
'\012', but I don't have an ascii table in front of me (I'm typing on a 
WinXP box at the moment!)

Barb Fox

At 06:25 PM 6/16/2005, you wrote:
>So the files I have been looking at were actually created on a mac, and 
>seem to only have the ^M.  If I remove the ^M I just get one big glob of text.
>
>I think I can figure something out using the solution Barb suggested, but 
>I don't have a terminal right now, so I'll have to play with it later.
>
>cheers,
>maria
>
>Mary wrote:
>>On Thu, Jun 16, 2005, Maria McKinley wrote:
>>
>>>I've never really thought about this before.  How are carriage returns
>>>marked in linux text files?  How would you substitute a ^M for a
>>>carriage return that more or cat would recognize?
>>
>>There are two different characters involved. There is the "carriage
>>return" character (ASCII character 13) and the "line feed" character
>>(ASCII character 10).
>>MS-DOS format text files have lines ending in two characters: carriage
>>return followed by line feed. (Some internet protocols including HTTP
>>follow this convention too.) UNIX format text files have lines ending in
>>one character, the line feed character. (According to [1] carriage
>>return takes the cursor all the way to the left, and line feed takes it
>>down a line. Line feed has both functions on UNIX.)
>>So as it turns out you almost never have to substitute in a new
>>character for more/less/cat/UNIX-y utilities to recognise it: the line
>>feeds are already there. You just strip the carriage returns.
>>-Mary
>>[1] http://www.jimprice.com/jim-asc.htm
>>_______________________________________________
>>Techtalk mailing list
>>Techtalk at linuxchix.org
>>http://linuxchix.org/cgi-bin/mailman/listinfo/techtalk
>
>_______________________________________________
>Techtalk mailing list
>Techtalk at linuxchix.org
>http://linuxchix.org/cgi-bin/mailman/listinfo/techtalk



More information about the Techtalk mailing list