Nov 22, 2009

How To Remove The ^m In Cpp Files ? - A^M at the end of each line in a source

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Operating Systems > Linux

How To Remove The ^m In Cpp Files ? - A^M at the end of each line in a source

jedipi
My friend just sent me a program source file.
It is a *.cpp file (C++ source).

When I open with text editor (gedit), there is a ^M at the end of each line.
Then I try vim and emacs. they just give me a same result.

What is that ^M???
Why does it there???
How can I delete them all (not one by one)???

Thank you.

Comment/Reply (w/o sign-up)

miCRoSCoPiC^eaRthLinG
I've seen that before and as far as I know - all the ^M-s represent the CR-LF combination of DOS. In DOS/Windows, a line is terminated by Carriage Return (CR) and Line Feed (LF) - whereas in *NIX platforms, a CR is enough to bring the cursor to the next line.

I think it's this discrepancy that renders the CR-LF combination as a ^M in gedit/vim etc. You can safely remove them. Simply do a mass search and replace and replace the ^M with a space. that'll be easier than deleting them from the end of each line manually.

Regards,
m^e

Comment/Reply (w/o sign-up)

saga
Just a thought..
What if after deleting those escape sequences (are they escape sequence?).....
ahhhhhh nevermind, yeah it wouldnt matter even if the compiler when parsing the code would ommit CR-LF becuase a statement is always terminated by semi-colon smile.gif how stupid of me smile.gif

Comment/Reply (w/o sign-up)

qwijibow
In Kedit (the KDE version of GNOME's Gedit, you can select MS-DOS character encoding.
can Gedit do the same ?

There is a command line tool that converts dos txt files to unix, but i just catn remember its name.. anyone ???

Comment/Reply (w/o sign-up)

yordan
Keep cool, man, most of the compilers simply ignore that ^M thing. It should only be a slight lack of comfort for you.
Here is how to make the mass substitution using vi (sorry, vi is very basic but some people still use it).
First open your file using vi. In a Unix window, type :
vi myfile.cpp

You will see the vi screen, not very comfortable but let's use it.
Type type following sequence. the sequence starts with (Esc) which is my way of saying that you must press the Escape key (at the upper left of your keybord). the escape key tells vi that you are entering the command mode, instad of the text browsing mode. type the following :
(Esc) :%s/(Ctrl-V)(Ctrl-M)//
(finishing with Enter, of course).
So, here :
(Ctrl-V) means, press and keep pressing the Ctrl key while pressing the v key.
(Ctrl-M) means, "press and keep pressing the control key while pressing the m key".
in the "%s" string, s means "Substitue" and "%" means "in the whole document).
/first/second/ means replace "first" by "second".
(Ctrl-V) means "what follows is a control sequence, accept it with executing it"
(Ctrl-M) is the control sequence for "next line"
so /(Ctrl-V)(Ctrl-M)/ which is the ^M you don't like, will be replaced with //, whic his nothing.
This is a very long explanation for the lot of things which will be done by the simple command line. Don't really worry about that long explanation, simply type my line :
(Esc) :%s/(Ctrl-V)(Ctrl-M)//

You will see all the ^M disappear. Then save your text and exit by typing
(Esc) :wq

(wq means : write and quit).

Hope this helped

 

 

 


Comment/Reply (w/o sign-up)

qwijibow
AHAAAAAAA.

found it, the tool to convert dos text files to unix is called..... "dos2unix"
it will probably be installed with your distro, if not i have attached th source code to this post.

install it like so...

CODE
gcc -O2 ./dos2unix.c -o ./dos2unix
su
<root password>
mv ./dos2unix /usr/bin

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : remove, cpp, files, end, line, source

  1. Linux And Windows Partitions
    Sharing files back and forth (2)
  2. Linux - Handy Tool If You Can't Unmount Due To Open Files
    (0)
    lsof The author of the article below says he uses lsof most for getting network connection
    related information from a system, but netstat is just as useful and made specifically for this
    particular purpose. lsof will do more than network connections, though. It will also tell you what
    files the program has open in addition to unix sockets and libraries. Of course you could also get
    all this from /proc but lsof makes it nice and easy. 'of' is actually for 'open
    files'. http://dmiessler.com/study/nix/commands/lsof/ or http://img231.imageshack.us/img2....
  3. Debian Users, Please Post Your Source List Here
    (3)
    Please copy/paste your /etc/apt/sources.list here.....
  4. Ubuntu Livecd
    Can't see all my files!!! (7)
    Hey, i got a Ubuntu LiveCD and it works perfectly. Seems like a good change from Windows from time
    to time. The only problem i am having is that i cant find some files that are on my C:/ drive (the
    Windows area) - although i can see them through windows no problem. Example is that when i go to the
    documents and settings folder on the C drive, no folders are there. When i go back to windows, its
    there! Can someone please tell me how can i see my files via ubuntu. I am quite a newbie to Ubuntu
    so please excuse me if this is a n00b question /tongue.gif" style="vertical-....
  5. File Rename Script, Sentence
    Large collection of files to rename! (7)
    Hello there, Today I've encoded lots of mp3's for my portable mp3 player (which only has
    128mb ... /blink.gif" style="vertical-align:middle" emoid=":blink:" border="0" alt="blink.gif" />),
    Anyway I encoded them with Lame using mlame script (for those don't know it handles more files
    then one). Now mlame appends "-new-converted-file" to the filename. And renaming every individual
    file with the hand is A LOT of work /mellow.gif" style="vertical-align:middle" emoid=":mellow:"
    border="0" alt="mellow.gif" />. I tried to write a script to remove that "-new-conv....
  6. Share Files With Samba
    (2)
    I've been asking along this week , how to set a authentication prompt on windows 2000
    professional , because i'm trying to create a secure file sharing cpu. Well... i remembered that
    linux is very great in stability and secure. I've downloaded and installed Mandriva 10.1 because
    he already brings Samba package, but i cant get him inside my workgroup, because he creates a
    defautl work group "mdkworkgroup" something like that. I'm not very expert in linux systems but
    i know that he can be configurated to Serv Files Sharing ( Only ). I know there are alots ....
  7. Fix Fedora 5 Add/Remove Software Problem
    fix the problem that cannot add/remove software without Internet conne (2)
    The add/remove software in Fedora 5 just does not work if you machine is not connected to the
    Internet. It wont add or remove any package for you even though you have the disks. If you read
    files in /etc/yum.repos.d/, you will understand. Fedora 5 will connect to redhat's website when
    you want to update your Fedora. Here is a simple way to update your fedora 5 via FC5 iso file. 1,
    move all files, which are under /etc/yum.repos.d directory, to other directory. for example, backup
    directory. 2. create a new directory *.reop in /etc/dym.repos.d Copy and Paste the ....
  8. Kernel Source To Compile Nvidia Drivers?
    (13)
    Ok, this is my new post since change of topic! /tongue.gif" style="vertical-align:middle"
    emoid=":P" border="0" alt="tongue.gif" /> Ok, I found out how to kill X server and that is good!
    Now, I need to figure out how to get the kernel source (?) to compile my NVIDIA drivers so I can
    start using linux out of 800x600 resoultion which is really bothering! If I could have some
    assistance please for getting the sources? My Debian version is the latest, 3.1. Thanks!! F....
  9. Play .avi Files In Redhat
    Need help in installing divX codecs... (6)
    The last few days have been spent in trying to get .avi files (Previously encoded using DivX codecs
    in Windows). I've a collection of movies that I've backed up as .avi files and I'm out
    of options trying one thing after another. So far: I have installed Helix player & Real Player; I
    have the DivX4Linux files but do not know how to install these (unlike configuring and 'make
    install' since there is no configure file and there are not instructions either). Also, Xine
    player (Xine-UI) which I've finally got working plays VCDs DVDs and Audio CD....
  10. .tcl Files, How To Open One?
    (2)
    Ok, after my first question about Linux here's already another one. I have some .TCL files that
    I have to open, do you know how to do that? I would realy appreciate any help. -=jeroen=-....
  11. Core.xxxx Files In /
    what are they?? (3)
    OS:red hat 9.0 There are thousands of core.xxxx files were found in the root directory (/)
    # ll |more total 3082181 drwxr-xr-x 2 root root 4096 May 30 23:45 bin drwxr-xr-x 4 root root 1024
    May 30 22:33 boot -rw------- 1 root root 442368 Jun 21 10:52 core.1002 -rw------- 1 root root 446464
    Jun 21 10:52 core.1003 -rw------- 1 root root 438272 Jun 21 10:52 core.1004 -rw------- 1 root root
    442368 Jun 21 10:52 core.1005 -rw------- 1 root root 446464 Jun 21 10:52 core.1007 -rw------- 1 root
    root 442368 Jun 21 10:52 core.1010 -rw------- 1 root root 446464 Jun 21 10:5....
  12. How Can I Hide Files And Processes In Linux?
    (3)
    Can any one tell me how to hide files and processes in Linux? for example, there is a *.exe file, I
    don;t want anybody to see it (just hide it), including use ls command. if I run this program, the
    process can be list by ps command. Is it possible to hide this process?? if yes, how to do that??
    Thank you.....
  13. Installing Mplayer 1.0 Pre7 From Source
    for new linux user (1)
    1.Intro: installation environment: FC3 This new version Mplayer can play rm file very well and
    many bugges were fixed. if you want to play stream media with mplayer, please download the package
    from live.com and put it to /usr/lib after compiled then when you compile Mplayer please use the
    following options --enable-live --with-livelibdir=/usr/lib/live 2.download: - MPlayer-1.0pre7
    ----------------- http://www4.mplayerhq.hu/MPlayer/releases/...1.0pre7.tar.bz2 - Codes --------
    i. CODES-all http://mplayer.ethz.ch/MPlayer/releases/co...0050412.tar.bz2 ii. win32_....
  14. My Own Source Package Managment
    (LFS and others), educational purpose... (3)
    Hi... some time ago I posted in my LFS/SE Linux topic that is my candidate to be something that
    can be used to build Source Package Managment for any distro, but it didn't realy fits there, so
    I decided to move to separate topic... Unfortuneatly running it would take long time, so then I
    was thinking about something like running make install with -n option and send results to file, then
    parse it for mkdirs, cps and other commands that installs aplication in file system, then if files
    already exists, ask to copy them, and then run make install without -n... but....
  15. [linux]need To Know Where To Find Rpm
    kernel-source-2.6.8.1-10mdk.i586.rpm (6)
    I am trying to install my video drivers, and I need the kernel source. I don't have it on my
    mandrake installation materials, and I need to know where I can find it.... Any Ideas would be
    very appreciated.........

    1. Looking for remove, cpp, files, end, line, source

See Also,

*SIMILAR VIDEOS*
Searching Video's for remove, cpp, files, end, line, source
advertisement



How To Remove The ^m In Cpp Files ? - A^M at the end of each line in a source

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com