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:
:%s/^M//g

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

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

Using dos2unix comand:
dos2unix filename newfilename

Examples:

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

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

45 comments:

ujjwal singh said...

Thanks Sujay,

Narasimha Rao said...


Ecorptrainings.com 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:

text1^Mtext2^Mtext3^M

How to remove these?

Desired content in the file
text1
text2
text3

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
:%s/\^\M//g

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

ORACLE FUSION PROCUREMENT said...

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...

NICE
http://spunksoft.com/course/sap-s4-hana-simple-finance-training-in-hyderabad/

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

Mouni yoga said...

This looks absolutely perfect. All these tiny details are made with lot of background knowledge. I like it a lot. 
python online training
python training in OMR
python training in tambaram

Deepika Analy said...

Appreciation for really being thoughtful and also for deciding on certain marvelous guides most people really want to be aware of.

UX Design Training
UX Design Training in Chennai

Amar G said...

UiPath Training in Bangalore by myTectra is one the best UiPath Training. myTectra is the market leader in providing Robotic Process Automation on UiPath
robotic process automation training in bangalore

Anexas Europe said...

Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
Good discussion. Thank you.
Anexas
Six Sigma Training in Abu Dhabi
Six Sigma Training in Dammam
Six Sigma Training in Riyadh

shethal said...

Thanks for your informative article, Your post helped me to understand the future and career prospects & Keep on updating your blog with such awesome article.
Devops training in sholinganallur
Devops training in velachery

cynthia williams said...

Thanks for sharing tips and tricks admin. It is really helpful, keep up the good work and share more like this.
RPA Training in Chennai
Robotics Process Automation Training in Chennai
RPA courses in Chennai
DevOps Training in Chennai
AWS Training in Chennai
Angularjs Training in Chennai

Sai Elakiyaa said...

Amazing post. It will be very helpful for beginners like me. Thank you very much for this kind of post.Waiting for your next blog.

Selenium training in Chennai
Selenium Courses in Chennai
best ios training in chennai
Digital Marketing Training in Chennai
JAVA J2EE Training Institutes in Chennai
Best PHP training in chennai
PHP Training

Shiva Shakthi said...

The information which you shared is very much intresting. Thanks for sharing the amazing blog.
Web Designing Course in Coimbatore
Web Design Training in Coimbatore
Web Designing Training Institute in Coimbatore
Web Design Training Coimbatore
Best Web Designing Institute in Coimbatore

Vicky Ram said...

Thanks for sharing this information.

Guest posting sites
Technology

Aruna Ram said...

Wonderful article!!! It is very useful for improve my skills. This blog makes me to learn new thinks. Thanks for your content.
CCNA Certification in Bangalore
CCNA Training Bangalore
CCNA Training institutes in Bangalore
CCNA Course in Kodambakkam
CCNA Training in Aminjikarai
CCNA Course in Chennai Kodambakkam

Anbarasan14 said...

Your blog is nice. I believe this will surely help the readers who are really in need of this vital piece of information. Thanks for sharing and kindly keep updating.

English Speaking Course in Bangalore
Best Spoken English Classes in Bangalore
Spoken English in Bangalore
Best Spoken English Training Center near me
Spoken English Institute in Chennai
English Coaching Classes in Chennai
Best Spoken English Class in Chennai

dinesh said...

This information is impressive. I am inspired with your post writing style & how continuously you describe this topic. Eagerly waiting for your new blog keep doing more.
Android Training in Bangalore
Android Course in Bangalore
Android Training Institutes in Bangalore
Best Android Training Institute in Bangalore
Android Classes in Bangalore
Aws Training Institutes in Bangalore
Aws Certification Training in Bangalore
Aws Training Center in Bangalore
hadoop institute in bangalore
best institute for bigdata in bangalore
big data coaching in bangalore

sharmi chithra said...

It is very excellent blog and useful article thank you for sharing with us, keep posting.

Primavera Training in Chennai
Primavera Course in Chennai
Primavera Software Training in Chennai
Best Primavera Training in Chennai
Primavera p6 Training in Chennai
Primavera Coaching in Chennai
Primavera Course

nanadhini chandran said...

This blog is more effective and it is very much useful for me.
we need more information please keep update more.
Salesforce Training in Thirumangalam
Salesforce Training courses near me
Salesforce Training in Vadapalani
Salesforce Training in Amjikarai

sharmi chithra said...

Nice post. By reading your blog, I get inspired .. Thank you for posting.

Informatica Training chennai
Informatica Training institutes in Chennai
Best Informatica Training Institute In Chennai
Best Informatica Training center In Chennai
Informatica institutes in Chennai
Informatica courses in Chennai
Informatica course
Informatica MDM Training in Chennai

vishnu said...

Thank you for sharing this valuable information. Keep up the good work.

Best Linux Training Institute in Chennai
Best Linux Training in Chennai
Learn Linux
Linux Training in Adyar
Linux Course in Velachery
Best Linux Training Institute in Tambaram