0

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.

shantanuo
  • 3,579
  • 8
  • 49
  • 66

2 Answers2

4

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

Suku
  • 2,036
  • 13
  • 15
  • 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
4

Translate has shown it's power!

tr -d "\r" 
shantanuo
  • 3,579
  • 8
  • 49
  • 66