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

  • Redis install steps on FreeBSD

      Install redis FreeBSD port collection: $ cd /usr/ports/databases/redis/ && make install clean # or with portmaster $ portmaster databases/redis   ===>  CONFIGURATION NOTE:   To setup “redis” you need...
  • How to Manage a Linux Server with systemd

    What Operating Systems Have Adopted systemd? CentOS: Yes, by default since CentOS 7 Fedora: Yes, since the release of Fedora 15 RedHat: Yes Debian: Yes, shipped since Debian 7 as...
  • 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...
  • How to List Which Apache 2 Modules are Enabled on CentOS 6.x

    View Loaded Apache Modules Just one command: apachectl -M Or, if you want to view the list in alphabetical order: apachectl -M | sort Or, if you want to view...