FreeBSD Linux Tips and Tricks

How to get rid of ^M characters.

When you edit a file in Windows and then open in UNIX, you must have seen ^M characters getting appended in the content. How to get rid of it ?

Most UNIX OS come with a utility called ‘dos2unix or dosunix (FreeBSD)’ . If it is not installed, please run following appropriate commands to install the utility and then convert appropriate file

  • Linux:

             yum install dos2unix

             dos2unix inputfile  >outputfile

  • FreeBSD:

            pkg install dosunix

            dosunix inputfile outputfile

Also, there are other ways to remove such characters as well:

  • Via Sed command:

           sed -e “s/^V^M//” inputfile > outputfile

          Note: Don’t paste the above command. Press Ctrl V and then Ctrl M in the above command instead.

  • Via vi editor:

    1. Open the file in vi.
    2. In the command mode, type :%s/^M//g.

          Note: Don’t type “^M”, but instead press “Ctrl V” and “Ctrl M” for it.

Related Articles

  • Add IP to CentOS 5/6

    If you recently got a secondary IP block for your server but you do not know how to bind the secondary IP address, please follow the steps below:   First, run...
  • Identifying malicious mail scripts on FreeBSD

    This article will help you identify an possible spam scripts that may be causing unwanted outbound mail which could cause your servers ip address to be blacklisted.There are many different...
  • Basic Linux commands

              In recent years, more people have begun to look into , explore, and try out the many features of Linux based operating System has to offer. One of the...
  • SSL Certificate Installation for Courier IMAP and POP

    This guide will provide you information on how to setup and configure SSL certificates for the courier IMAP mail server.   Prior to the installation you will need to purchase...