Converting Windows file to Unix files

Thought I'd make a quick note about converting Windows files to Unix to remove the Carriage Returns from the file (which appear as ^M on the screen)

  1. Use dos2unix to create a new file without the ^M and then move it back over the original
    $ dos2unix original_file.txt > original_file.txt.convert
    $ mv original_file.txt.convert original_file.txt
  2. Use global search and replace in vi
    :%s/^M//g
    Note that the ^M above is done using CTRL-V CTRL-M
    ie :%s/{CTRL-V}{CTRL-M}//g

0 comments:

All views on this blog are my own. All hints, tips and scripts should be run and tested on your development and test servers before attempting in production.

About this blog

I have been DBA with over 10 years experience in Oracle. This blog aims to note interesting bits and pieces that I come across on a day to day basis.