Skip to content Accesskey=4Skip to sub-navigation Accesskey=3View our Accessibility Options MIT Information Systems Home About IS&T Contact IS&T Site Map Search Advanced Search
Getting StartedGetting Services by Topic or Alphabetically Getting Help

On This Page

[Help]

  

Quick Links

Top Level

Related Links

Ask OLC a question

Athena Consulting Homepage

Helpdesk Stock Answers (for Mac/PC questions)


How to remove ^M's from a file (CLEAN)

To remove '^M' (control-M) characters from the end of each line in a file, you
can use a shell script called 'clean'.

To use the shell script, you first need to attach the Consultants' Software
Library to your workstation.  Use this command:

	add consult

Now you can type this command:

	clean filename > newfilename

...where 'filename' is the name of the file containing the '^M' characters,
and 'newfilename' is the name of the file that you want the 'clean' script to
create.

The script takes 'filename' as input, changes each ^M to a newline character,
and directs the output to the new file called 'newfilename'.  You can check
that the new file contains no '^M' characters by viewing it with this command:

	cat -v newfilename

You can also remove all the control-M characters inside Emacs, though
it's a little tricky because Emacs tries to be helpful and treat
different OS-style line breaks transparently.  To use Emacs to make
the replacement, follow these steps:

1. type: 

        C-x RET C undecided-unix RET C-x C-w RET y

2. go to the beginning of the document

3. type:

	M-x replace-string RET C-q C-m RET RET

   where "RET" means <press the RETURN key> and things like C-q mean
   "hold control key and press the q" key.

MIT Home | Getting Started | Getting Services | Getting Help | About IS&T | Accessibility
Ask a technology question or send a comment about this web page.