Remove WhiteSpce From Unix File

Posted on 2011-05-02
Last Modified: 2012-05-11
Every line in my file has this at the end: ^M

I used to know a command to remove this, but forgot.

Please assist.
Question by:deharvy
    LVL 18

    Assisted Solution

    by:Raheman M. Abdul
    cat FILENAME|sed "s/^M//g">File2
    mv File2 File1
    LVL 18

    Accepted Solution

    You can also try dos2unix command

    dos2unix DOS-FILENAME filename

    and then

    mv filename DOS-FILENAME
    LVL 18

    Assisted Solution

    by:Raheman M. Abdul
    Another way within vi editor
    Using sed command

    sed 's:\^M::g' FILENAME


    Author Closing Comment

    dos2unix is the command I was thinking about. Thanks!

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Suggested Solutions

    Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. Please see for the updated article. It is avail…
    I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now