Command to remove ^M characters


                This blog entry is for those who are frustrated by removing ^M (Control M) characters. Usually ^M character will appear in the end of each ASCII file that is transferred from DOS to *NIX based system. Have a look at to know the reason for the same.

                I usually do my development in Windows and transfer it to *NIX based system for testing. Due to this I frequently hit with this problem and I was hunting for a command that will run over a set of directory and remove all the ^M characters. Finally I ended with “find “<location>” -name “*” -print | xargs perl -i -pe ‘s/\r\n/\n/g’”. This command is really superb it uses the standard set of commands to do the job. Thanks to hundreds of bloggers who gave hint for the above command. 

Note: You have to replace <location>, with the location of the directories containing files with ^M characters


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: