Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

up vote 4 down vote accepted

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

:%s/Ctrl+VCtrl+M//g

This will remove all those ^M

OR

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

 
discard

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.