dos2unix command emulation in Linux

When you create a file in windows OS and you copy the file in Unix and Linux servers, you would find that there are ^M character showing up. Ineterestingly they do not show up in more command but certainly in vi editor.

to convert such a dos file to unix format, solaris has a dos2unix command and also vice versa but this command does not exist in Linux mostly. (I couldn’t find in SLES for system-z).

The trick is to run the following command:

mv sync-it.sh sync-it.sh.bak; tr -d '\r' < sync-it.sh.bak > sync-it.sh

The above example converts the file sync-it.sh from DOS(Carriage return and line break both) format to UNIX(line break only) format.

* carriage return is represented by ‘\r’ and
* line break by ‘\n’

About

View all posts by

Leave a Reply

Your email address will not be published. Required fields are marked *