9

Suppose you are working on a very old unix server where dos2unix, perl, tr, and sed are not present. How can you convert files from dos to unix format?

Hemant
  • 6,910
  • 5
  • 39
  • 42

2 Answers2

12

I think you are referring to removing the caret-M at the end of lines. You can use search and replace in vi to do this.

In vi I normally do: (where "^" represents CTRL):

:%s/^V^M//g

Which shows on the screen as:

:%s/^M//g
jjclarkson
  • 2,147
6

A server without tr or sed would have to be really old, or missing some basic commands. Hopefully ed is there; it existed in Unix first edition.

ed /path/to/file
1,$s/^V^M$//
w
q

where ^V^M means typing Ctrl+V then Ctrl+M (to enter a literal line feed). If you know that all lines do end in CR LF, you can use 1,$s/.$// instead (indiscriminately remove the last character on each line).