Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a tab delimited text file. When I open the file with vi editor, I can see ^M character (in blue color). This is not part of my data. It got there because the original SQL data had carriage return /r sign.

713498  29195   NWSO    NE SA COLLEGE  2       O-      0.3     0.3     0.0     1               MHR     N       Y       Y       ^M      aher

How do I remove this character without affeting the tab locations? In other words there should be 2 tabs between the last Y and "aher" word.

share|improve this question
up vote 4 down vote accepted

In vi you can replace all ^M characters with command mode


This will remove all those ^M


You can do it with sed also:

sed -i 's/Ctrl+VCtrl+M//g' filename

share|improve this answer
For versions of sed such as GNU sed which support it, you can use the escape representation of a carriage return: sed -i 's/\r//g'. The same is true of vi. – Dennis Williamson Jan 18 '13 at 14:53

Translate has shown it's power!

tr -d "\r" 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.