Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I was editing a file in various programs such as gedit, kword, vim, emacs, and using cat to view the file to see which worked best and what differences between them. Now when I use vim to view the file, "^M" appears at the end of every line where it didn't before I opened it up in the other programs. The strange thing is that using cat, gedit, kword, etc. to view the file doesn't show these characters. What is this, and why is it only in vim?
It's a carriage return and probably means you're editing a DOS file. To be honest, sometimes it opens with '[dos format] and sometimes it shows the ^M. Not sure what the deal is there. Anyway - you can strip them with a ':%s/<ctrl-v><enter>$//'.
I might be wrong about the details, but point is, vim just shows superfluous returns and they can be stripped. Or left, if you wish.
Ah, ok. I had forgotten that the original file was sent to me from someone running Windows before I did all the editing in those programs. So I'm confused... are the ^M's part of the file or not? I don't think they are since cat doesn't show them, but if they aren't part of the file how can I strip something that isn't there . Sorry for my lack of understanding, I just don't know how these DOS files in Linux work. Thanks again.
They're there but they're non-printable characters. Vim's showing a control-character representation of them and the others aren't. Try 'cat -v <file>' and you'll see them there, too. xxd <file> shows '0d0a' whereas a *nix file will show '0a' at line endings. (I think.) That's what's 'really' in the file. Just indicates cr-lf vs. lf to mark line endings.
EDIT:
Hmm, I'm having trouble stripping those. I was trying to type the ^M and <ctrl-v> gives me a "^" with the cursor on top of it. If I type "m" or <shift-m> it just replaced that "^" with that letter.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.