How to replace ^M with a Hard Return with "sed"? - shell
This is a discussion on How to replace ^M with a Hard Return with "sed"? - shell ; Dear Everyone: I am using a "Mac OS X" machine and work in an X11 window. I got an ASCII file from someone, and when I "more" the file, the entire file shows up as one continuous stream interpersed with ...
![]() |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| |||
| |||
| I am using a "Mac OS X" machine and work in an X11 window. I got an ASCII file from someone, and when I "more" the file, the entire file shows up as one continuous stream interpersed with ^M (Control-M which is the line-separator). Now I can use the following command % sed '/s/^M//g' filename > newfilename to get rid of the ^M signs, but the resulted new file is in one continuous line. My intention, however, is to replace each ^M with a hard return. So my question: How do I represent the "hard return" in the above "sed" command? (which needs to be put between the last two slashes in the above command.) Thank you for reading and replying! --Roland |
|
#2
| |||
| |||
|
qquito ÐÉÛÅÔ: > Dear Everyone: > > I am using a "Mac OS X" machine and work in an X11 window. > > I got an ASCII file from someone, and when I "more" the file, the > entire file shows up as one continuous stream interpersed with ^M > (Control-M which is the line-separator). Now I can use the following > command > > % sed '/s/^M//g' filename > newfilename > > to get rid of the ^M signs, but the resulted new file is in one > continuous line. My intention, however, is to replace each ^M with a > hard return. > > So my question: How do I represent the "hard return" in the above > "sed" command? (which needs to be put between the last two slashes in > the above command.) > > Thank you for reading and replying! > col -bx < file > newfile But I don't known that exist `col' on MacOS or not. -- UV-RIPE |
|
#3
| |||
| |||
|
In article Michael Vilain > cat filename | tr "\r" "\n" > newfilename BTW, you can do it without the cat and pipe like this: tr '\r' '\n' < inputfile > outputfile -- Send responses to the relevant news group rather than email to me. E-mail sent to this address may be devoured by my very hungry SPAM filter. Due to Google's refusal to prevent spammers from posting messages through their servers, I often ignore posts from Google Groups. Use a real news client if you want me to see your posts. JR |
|
#4
| |||
| |||
|
Michael, Jolly and Vladimir: Thank you very much for your replies! In my case, I found Jolly's suggestion, "tr '\r' '\n' < inputfile > outputfile", works the best. --Roland On Nov 13, 3:25*am, Vladimir Usenko > qquito ÐÉÛÅÔ: > > > > > Dear Everyone: > > > I am using a "Mac OS X" machine and work in an X11 window. > > > I got an ASCII file from someone, and when I "more" the file, the > > entire file shows up as one continuous stream interpersed with ^M > > (Control-M which is the line-separator). Now I can use the following > > command > > > * % sed '/s/^M//g' filename > newfilename > > > to get rid of the ^M signs, but the resulted new file is in one > > continuous line. My intention, however, is to replace each ^M with a > > hard return. > > > So my question: How do I represent the "hard return" in the above > > "sed" command? (which needs to be put between the last two slashes in > > the above command.) > > > Thank you for reading and replying! > > * col -bx < file > newfile > But I don't known that exist `col' on MacOS or not. > > -- > UV-RIPE |
|
#5
| |||
| |||
|
In article Vladimir Usenko > col -bx < file > newfile > But I don't known that exist `col' on MacOS or not. It does indeed. Learn something new every day. "Half-reverse linefeed" indeed. I've never been a troff guy. <http://developer.apple.com/documenta...ManPages/man1/ col.1.html> -- W. Oates |
|
#6
| |||
| |||
|
In article Vladimir Usenko > qquito Ô˯ÂÚ: > > Dear Everyone: > > > > I am using a "Mac OS X" machine and work in an X11 window. > > > > I got an ASCII file from someone, and when I "more" the file, the > > entire file shows up as one continuous stream interpersed with ^M > > (Control-M which is the line-separator). Now I can use the following > > command > > > > % sed '/s/^M//g' filename > newfilename > > > > to get rid of the ^M signs, but the resulted new file is in one > > continuous line. My intention, however, is to replace each ^M with a > > hard return. > > > > So my question: How do I represent the "hard return" in the above > > "sed" command? (which needs to be put between the last two slashes in > > the above command.) > > > > Thank you for reading and replying! > > > > col -bx < file > newfile > But I don't known that exist `col' on MacOS or not. Open Terminal.app and type "man col". It's there. |
|
#7
| |||
| |||
|
Steve Hix ÐÉÛÅÔ: > In article > Vladimir Usenko > >> qquito Äù?ôË: >>> Dear Everyone: >>> >>> I am using a "Mac OS X" machine and work in an X11 window. >>> >>> I got an ASCII file from someone, and when I "more" the file, the >>> entire file shows up as one continuous stream interpersed with ^M >>> (Control-M which is the line-separator). Now I can use the following >>> command >>> >>> % sed '/s/^M//g' filename > newfilename >>> >>> to get rid of the ^M signs, but the resulted new file is in one >>> continuous line. My intention, however, is to replace each ^M with a >>> hard return. >>> >>> So my question: How do I represent the "hard return" in the above >>> "sed" command? (which needs to be put between the last two slashes in >>> the above command.) >>> >>> Thank you for reading and replying! >>> >> col -bx < file > newfile >> But I don't known that exist `col' on MacOS or not. > > Open Terminal.app and type "man col". > > It's there. I was saying that "I dunno about it" because I not have access and not working with MacOS... (I don't clean all newsgroup before sending answer). -- UV-RIPE |
|
#8
| |||
| |||
| Quote:
Code: sed -i 's/^M//' filename |
|
#9
| |||
| |||
|
On Wed, 12 Nov 2008 23:15:45 -0800 (PST), qquito wrote: > Dear Everyone: > I am using a "Mac OS X" machine and work in an X11 window. > I got an ASCII file from someone, and when I "more" the file, the > entire file shows up as one continuous stream interpersed with ^M > (Control-M which is the line-separator). Now I can use the following > command > % sed '/s/^M//g' filename > newfilename > to get rid of the ^M signs, but the resulted new file is in one > continuous line. My intention, however, is to replace each ^M with a > hard return. > So my question: How do I represent the "hard return" in the above > "sed" command? (which needs to be put between the last two slashes in > the above command.) The ^M is already a hard return. The problem is that Mac OS X is a Unix system, and like all Unix systems, it uses line feeds, not carriage returns, to mark the ends of lines. A command that will do what you want is: tr '\r' '\n' which says to convert all carriage returns into line feeds. -- Dave Seaman Third Circuit ignores precedent in Mumia Abu-Jamal ruling. |
|
#10
| |||
| |||
|
In article Vladimir Usenko > Steve Hix Ô˯ÂÚ: > > In article > > Vladimir Usenko > > > >> qquito ”õ?íÍ: > >>> Dear Everyone: > >>> > >>> I am using a "Mac OS X" machine and work in an X11 window. > >>> > >>> I got an ASCII file from someone, and when I "more" the file, the > >>> entire file shows up as one continuous stream interpersed with ^M > >>> (Control-M which is the line-separator). Now I can use the following > >>> command > >>> > >>> % sed '/s/^M//g' filename > newfilename > >>> > >>> to get rid of the ^M signs, but the resulted new file is in one > >>> continuous line. My intention, however, is to replace each ^M with a > >>> hard return. > >>> > >>> So my question: How do I represent the "hard return" in the above > >>> "sed" command? (which needs to be put between the last two slashes in > >>> the above command.) > >>> > >>> Thank you for reading and replying! > >>> > >> col -bx < file > newfile > >> But I don't known that exist `col' on MacOS or not. > > > > Open Terminal.app and type "man col". > > > > It's there. > I was saying that "I dunno about it" because I not have access and not > working with MacOS... (I don't clean all newsgroup before sending answer). Not a problem. I just noted that it was in MacOS X, and where one could get use information at the same time. |
![]() |
« Previous Thread
|
Next Thread »
| Thread Tools | |
| Display Modes | |
| |
All times are GMT -4. The time now is 11:02 PM.





Linear Mode