how to remove ctrl+M character from makefiles?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bajajv
    New Member
    • Jun 2007
    • 152

    how to remove ctrl+M character from makefiles?

    Hi,
    I am using windows and cygwin. I have hundreds of makefiles in my project folder, but the problem is that these makefiles contain a ctrl+M character when I open them in cygwin bash vim editor. Because of this I am not able to build any of my makefiles.
    Is there any command which could remove this character from all the makefiles in a folder?
    Otherwise, in a c program, how can I search for the ctrl+M character..
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    In C you can just search for the character value 26. How are ctrl-M characters getting into your files anyway?

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      Control-M is CR in ASCII encoding.

      Different platforms have different conventions for end-of-line termination of text files.
      • UNIX: LF
      • Windows: CR+LF
      • MacOS: CR


      Most likely your make files were created on a Windows machine but you are now trying to use them on a UNIX machine. You may have a pair of utilities already installed: dos2unix and unix2dos. These utilities translate end-of-line sequences in text files.

      By the way, printf("\n"); emits the platform-specific end-of-line sequence.

      Comment

      • bajajv
        New Member
        • Jun 2007
        • 152

        #4
        Originally posted by donbock
        Control-M is CR in ASCII encoding.

        Different platforms have different conventions for end-of-line termination of text files.
        • UNIX: LF
        • Windows: CR+LF
        • MacOS: CR


        Most likely your make files were created on a Windows machine but you are now trying to use them on a UNIX machine. You may have a pair of utilities already installed: dos2unix and unix2dos. These utilities translate end-of-line sequences in text files.

        By the way, printf("\n"); emits the platform-specific end-of-line sequence.
        Well yes, I was using windows files in unix.

        But downloaded the code again with unix format option selected in cvs, so no problem now.

        dos2unix and unix2dos were not available in the bash I am using.

        Comment

        • mac11
          Contributor
          • Apr 2007
          • 256

          #5
          see here for vim tips if you don't have dos2unix/unix2dos:
          Vim recognizes three file formats (unix, dos, mac) that determine what line ending characters (line terminators) are removed from each line when a file is read, or are added to each line when a file is written. A file format problem can display ^M characters, or can prevent scripts from running correctly. This tip explains how to avoid problems, and how to convert from one file format to another. Use of the 'fileformat' and 'fileformats' options is also explained. See below if all you want...

          Comment

          • Oralloy
            Recognized Expert Contributor
            • Jun 2010
            • 988

            #6
            There is a vi/vim sequence, which I often use to remove the extraneous carriage returns in individual files.

            :%s/^V^M//g

            where ^V and ^M are <ctrl-V> and <ctrl-M>, respectively.

            And yes, I realize that this solution is not viable for bulk file processing, although you might be able to use sed for that.

            Comment

            • Banfa
              Recognized Expert Expert
              • Feb 2006
              • 9067

              #7
              That's what I like about vim, the commands are so intuitive :D

              And yes I do see that it is actually a RegEx

              Comment

              • Oralloy
                Recognized Expert Contributor
                • Jun 2010
                • 988

                #8
                Not only intuitive after 30 years of use, but they were mnemonic from the start, which is why I still love and use vi. *grin*

                Comment

                Working...