ÄûÃÊÊÓƵ

print friendly version

Questions and answers

168
Why might I be having a problem with a text file on the Unix system?


The commands described below need to be entered while logged in to the Unix server.   Normally you'll see a prompt ending with $ when the command interpreter (or shell) is ready for another command.

The ^M often seen at the ends of lines in text files on the Unix system is a redundant carriage return character which has been introduced as a result of transferring from another system such as DOS or Windows. This is often caused by transferring a plain text file, via FTP, as a binary file. Lines in DOS and Windows plain text files end with a carriage return and a line-feed (CRLF); those in UNIX text files end with just carriage-return (CR).

There is a command on the IT Services Unix system called dos2unix which will remove these characters. Type the command

dos2unix -ascii -437 myfile myfile

where myfile is the name of the file to be converted (note that you need to enter the name twice as shown).

The reverse (converting a text file from Unix format to Microsoft text format) can be achieved by using the command

unix2dos myfile myfile

where myfile is the name of the file to be converted.

For more information on either of these commands, enter the command

info dos2unix

or

info unix2dos

 

Help us to improve this answer

Please suggest an improvement
(login needed, link opens in new window)

Your views are welcome and will help other readers of this page.

Categories

This is question number 168, which appears in the following categories:

Created by Andy Clews on 27 July 2001 and last updated by Andy Clews on 4 August 2015