+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13

How to replace ^M with a Hard Return with "sed"?

  1. How to replace ^M with a Hard Return with "sed"?

    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!

    --Roland

  2. Re: How to replace ^M with a Hard Return with "sed"?

    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. Re: How to replace ^M with a Hard Return with "sed"?

    In article ,
    Michael Vilain wrote:

    > 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. Re: How to replace ^M with a Hard Return with "sed"?

    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 wrote:
    > 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. Re: How to replace ^M with a Hard Return with "sed"?

    In article ,
    Vladimir Usenko wrote:

    > 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. Re: How to replace ^M with a Hard Return with "sed"?

    In article ,
    Vladimir Usenko wrote:

    > 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. Re: How to replace ^M with a Hard Return with "sed"?

    Steve Hix :
    > In article ,
    > Vladimir Usenko wrote:
    >
    >> 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. Re: How to replace ^M with a Hard Return with "sed"?

    Quote Originally Posted by qquito View Post
    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!

    --Roland
    Code:
    sed -i 's/^M//' filename
    to get the ^M you have to type ctrl+v+m

  9. Re: How to replace ^M with a Hard Return with "sed"?

    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' newfile

    which says to convert all carriage returns into line feeds.

    --
    Dave Seaman
    Third Circuit ignores precedent in Mumia Abu-Jamal ruling.


  10. Re: How to replace ^M with a Hard Return with "sed"?

    In article ,
    Vladimir Usenko wrote:

    > Steve Hix ˯:
    > > In article ,
    > > Vladimir Usenko wrote:
    > >
    > >> 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.

+ Reply to Thread
Page 1 of 2 1 2 LastLast