By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,688 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,688 IT Pros & Developers. It's quick & easy.

removing ^m char

P: 8
I have uploaded one txt file from windows to unix.when i am opening the file
in vi editor at the end of every line it is giving ^m char.

can any one tell me what is the procedure to remove ^m char from my txt file.

Regards
Anutosh
Jul 11 '08 #1
Share this Question
Share on Google+
4 Replies

Nepomuk
Expert 2.5K+
P: 3,112
Well, you could just remove it with vi, but I'm guessing it's not only on this file or the file is very big?
In that case, you could try the following bash script:
Expand|Select|Wrap|Line Numbers
  1. while read line; do echo "${line%%^m}"; done < <(cat file.txt) > new_file.txt
(file.txt being your old file and new_file.txt being the new one)

Hope it works.

Greetins,
Nepomuk
Jul 11 '08 #2

100+
P: 256
you probably have a utility called dos2unix on your unix machine which will do that for you

google found this summary page for me, but you can probably just run man for it yourself
http://linux.about.com/od/commands/l...l1_dos2uni.htm
Jul 11 '08 #3

P: 32
you probably have a utility called dos2unix on your unix machine which will do that for you

google found this summary page for me, but you can probably just run man for it yourself
http://linux.about.com/od/commands/l...l1_dos2uni.htm
If you just want to do this while vi is open ...

You can just do this :

1. open file in vi
2. type this --> :%s/<Ctrl+V><Ctrl+M>// ----> then hit Enter

Where the <Ctrl+V> command is ... hold the Ctrl button and press the V key
and the same goes for the <Ctrl+M> command.

The <Ctrl+V> command will insert this character '^'
The <Ctrl+M> command will insert the 'M' character (which stands for a carraige return in dos)
Jul 11 '08 #4

gpraghuram
Expert 100+
P: 1,275
i think dos2unix is the best option for this.

Raghu
Jul 14 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.