Saturday, April 2, 2011

How to remove CONTROL-M characters in UNIX or Linux

Control-m characters will get appended to a file when a file is transferred from windows to UNIX machine. There are multiple ways it can be removed.

Using vi editor:

Using col command:
cat filename | col -b > newfilename

Using sed command:
sed 's/^M//g' filename > newfilename

Using dos2unix comand:
dos2unix filename newfilename


volcano@volcano-laptop:~/shellscript/ctrl$ cat -v jsk
volcano@volcano-laptop:~/shellscript/ctrl$ cat jsk | col -b >
volcano@volcano-laptop:~/shellscript/ctrl$ cat -v
volcano@volcano-laptop:~/shellscript/ctrl$ sed 's/^M//g' jsk > jsk.new2
volcano@volcano-laptop:~/shellscript/ctrl$ cat -v jsk.new2

Note: Hold the control key and then press v and m to get the control-m character


ujjwal singh said...

Thanks Sujay,

Narasimha Rao said... provides CONTROL-m in hyderabad with best faculties on real time projects. We give the best online trainingamong the CONTROL-m in Hyderabad.
Classroom Training in Hyderabad India

venkatesh reddy said...

using any of the above command(sed,dos2unix,etc) i am not able clear CONTROL-M characters. Please suggest us to solve this issue.

Murali said...

Great job! thanks a million !!
I used the following command from the above and it worked like a champ. I am on AIX 6.1

cat filename | col -b > newfilename

Thanks a lot!!!!

mahasiswa teladan said...

hi...Im student from Informatics engineering nice article,
thanks for sharing :)

rahim said...

Very goo, Thanks :)

James Sa said...

why dos2unix doesn't remove ^M if the dos text file has ^M without line feed?

Seshank satavilli said...

I am not able to remove the ^M characters.

the contents of the file:


How to remove these?

Desired content in the file

Thanks in advance.

Bogon said...

For the inline ^M, you can use this:

$ sed 's/\cM/\n/g' file.txt > newfile.txt

This assumes that your text stream ends with a newline (conventionally \n)

murali krishna said...

Command suggested through vim doesnt work. Instead try this

Sri said...

I have tried Col option which really helped me. Thanks much

joshnson haddin said...

A guarantee of appreciation is oracle training in chennai all together for sharing the key data and its really stunning.informatica training in chennai


good explanation has been given about Linux.This is the best article i have seen
about Linux.thanks for giving good explanation.
oracle fusion procurement online training

Calfre India said...

Oracle fusion financials online training institute we have our branch over all the india. Oracle Fusion Financials Online Training in Hyderabad, Bangalore, Delhi, Chennai, Kolkata, Pune, Mumbai, Ahmedabad, Gurgon, Noida, India, Dubai, UAE, USA, Kuwait, UK, Singapore, Saudi Arabia, Canada, Oracle Fusion financials Online Trainings

Oracle fusion Financials Online Training

Oracle Fusion Financials online Training

Priya Kannan said...

I just see the post i am so happy the post of information's.So I have really enjoyed and reading your blogs for these posts.Any way I’ll be subscribing to your feed and I hope you post again soon.
UNIX Training in Chennai

oracle34 said...

thank for sharing use full information for more
Attend free demo classes at igofusion for Oracle Fusion Financials coaching

suresh H said...

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info.
Best AngularJS Training in Chennai
Hadoop Training in Chennai
Big Data Training in Chennai

Sandeep Oracle said...

That is a good tip, especially to those new to the blogs here but very accurate information. Very nice blog post!! Thanks for the posting that is a really neat written blog..........Visit our website known about Fusion SCM Training in Ameerpet Hyderabad.

sravanthi said...

Really very helpful article , Thank you for sharing.

Oracle Fusion Technical Training In Hyderabad

oracle calfre said...

Search for Oracle Training Institute details in our local search engine Calfre.

Unknown said...

Thanks for posting the blog. I felt comfortable while reading the post. Keep posting more blogs.
we are the best CALFRE Search Engine search about all different courses in Al Karama, Dubai Locations. For Example Search a course like Oracle SQL Training Know More Click Here

calfre search said...

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. Your write up is a fine example of it.

Oracle Fusion SCM Training in Hyderabad

cal fre said...

Hi, Thanks for sharing a nice information of the blog.
It's really nice blog. For more info please visit.
IOT Training Institutes in Ameerpet

aravind g said...


amilu B said...

I really like your blog. You make it interesting to read and entertaining at the same time. I cant wait to read more from you.

python training in omr

python training in annanagar | python training in chennai

python training in marathahalli | python training in btm layout

python training in rajaji nagar | python training in jayanagar

simbu said...

Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

java training in omr

java training in annanagar | java training in chennai

java training in marathahalli | java training in btm layout

java training in rajaji nagar | java training in jayanagar

Anexas Europe said...

It’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read.

Digital Marketing Training in Mumbai

Six Sigma Training in Dubai

Six Sigma Abu Dhabi

shalinipriya said...

Excellent blog, I wish to share your post with my folks circle. It’s really helped me a lot, so keep sharing post like this

Data Science Training in Chennai
Data science training in bangalore
Data science online training
Data science training in pune
Data science training in kalyan nagar
selenium training in chennai

Saro said...

Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

rpa training in Chennai | rpa training in velachery

rpa training in tambaram | rpa training in sholinganallur

rpa training in Chennai | rpa training in pune

rpa online training | rpa training in bangalore