Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

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?

share|improve this question
sed is allowed? – elmarco Aug 12 '10 at 15:11
@elmarco: no :( – Hemant Aug 12 '10 at 15:20
How old does a unix server have to be to not have tr and sed ? sed is old........ iirc, – xenoterracide Nov 7 '10 at 23:25
Would ex or ed be available on a system like that? I would'nt call it unix if there is no tr or sed. – MattBianco Mar 31 '11 at 6:52
No sed? Really!? Out of interest, what is the system? As Gilles and MattBianco point out, it would probably still have ed at least. – Mikel Mar 31 '11 at 21:03
up vote 11 down vote accepted

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):


Which shows on the screen as:

share|improve this answer
thanks that worked :). I think its a very portable solution. – Hemant Aug 12 '10 at 16:06
You can also use sed to do the same thing w/out having to vim the file: sed -e '%s/^V^M//g' filename That also will show on the screen as sed e '%s/^M//g' filename In general, if you can search/replace it in vim, the command is virtually the same in sed. – gabe. Aug 12 '10 at 19:09
@gabe: the sed solution is actually even more portable +1 :) – wzzrd Aug 12 '10 at 20:54
@wzzrd, sed and vi are both specified by POSIX, and that vi command doesn't use any Vim extensions. – Wildcard Apr 16 at 2:11
@jjclarkson what does ^V and '^M' mean? – cokedude Apr 28 at 22:10

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

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).

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.