DelphiFAQ Home Search:
General :: Linux :: shell
Linux shell programming/ scripting, shortcuts and general know-how.


This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Converting Mac style text files to Unix style


I moved a folder of HTML files from a Mac to a Unix box and now the files look messy. I see lots of ^M characters in vi. How can I clean it up?


Applications on the Mac platform usually use carriage returns (#13 or ^M) as line separators.
Windows applications use carriage return + line feed (#13#10 or ^M^J).
Unix applications use only line feed (#10, ^J)

The best thing to do is to configure your ftp tool (e.g. Dreamweaver) to send files 'ASCII' style.

You can also use the following unix command to edit your file. The '\r' is the carriage return, replaced by a newline '\n'

The second command does the same, using perl instead.

If your Linux installation has the tool mac2unix (e.g. in /usr/bin) then you may use this tool. It can take wildcards!

tr '\r' '\n' <index.html >index2.html
 perl -p -e 's/\r/\n/g'  <index.html >index2.html
 // convert all html files using /usr/bin/mac2unix
 mac2unix *.html
 // recursively convert all html files in subdirectories
 find . | mac2unix

Generated 16:00:41 on Oct 16, 2017