Facebook Twitter Instagram
    WiredRevolution.com
    • Home
    • About
    • Contact Us
    • Essential Linux Commands
    • Sitemap
    Facebook Twitter Instagram
    WiredRevolution.com
    system administration

    Remove Windows carriage returns with tr

    RyanBy RyanNovember 30, 2008Updated:January 7, 20091 Comment2 Mins Read
    Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Email

    The end of a line in a UNIX text file is designated with the newline character. In Windows, a line ends with both newline and carriage return ASCII characters. If a file is saved in Windows and then moved to a Linux system these carriage returns can cause all sorts of problems. If the text file is a BASH script for example it will not run correctly since it doesn’t know how to interpret these characters.

    You can verify that a text file has these Windows carriage returns by running the cat command with the ‘-v‘ option which shows the non-printing characters.

    $ cat -v inputfile | head
    
    first line^M
    second line^M
    

    You can see the carriage return characters, “^M” (Cntl-M).

    CRLF = Carriage Return Line Feed

    There are various was to remove these carriage returns. You can use the dos2unix command but this is rarely installed by default on a a Linux system. The easiest way then is to use the “tr” command utility which always comes standard.

    The command uses the tr command which translates and removes characters. This will remove the carriage return characters.

    $ tr -d '\r' < inputfile > outputfile
    

    You can verify they are really gone by running the same cat command again.

    $ cat -v outputfile | head
    
    first line
    second line
    

    You can also run the file command.

    $ file inputfile
    
    inputfile:             ASCII text
    

    Optionally you can now overwrite the original file.

    $ mv outputfile inputfile
    
    Share. Facebook Twitter Pinterest LinkedIn WhatsApp Reddit Email
    Previous ArticleDownload digital camera photos with gphoto2
    Next Article How to X session forwarding over SSH

    Related Posts

    Safely and atomically change a symlink target

    ASCII HTML Reference Chart

    Google Chrome Text Highlight Searching and Navigation

    Most Commented
    March 12, 2009

    Fix blue tinted video in Ubuntu

    September 10, 2010

    Setup SSH access between VirtualBox Host and Guest VMs

    March 8, 2011

    Install GNOME Shell in Ubuntu 10.10 Maverick

    April 4, 2009

    Setup the PS3 Bluetooth Controller on Ubuntu

    October 22, 2008

    How to correctly use LD_LIBRARY_PATH

    Recent Comments
    • Execute command on linux virtual machine (or server) from windows commandline on Setup SSH access between VirtualBox Host and Guest VMs
    • Solved: How to SSH to a VirtualBox guest externally through a host? - Daily Developer Blog on Setup SSH access between VirtualBox Host and Guest VMs
    • How to SSH to a VirtualBox guest externally through a host? [closed] – Code D3 on Setup SSH access between VirtualBox Host and Guest VMs
    • How to copy and paste from VirtualBox? [duplicate] on Setup SSH access between VirtualBox Host and Guest VMs
    • Jackie Laguna on Fix OpenGL: ChoosePixelFormat SketchUp error in WINE
    © 2026 ThemeSphere. Designed by ThemeSphere.

    Type above and press Enter to search. Press Esc to cancel.