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

    Convert text files within a directory from Windows to Unix format

    RyanBy RyanJanuary 7, 2009Updated:January 13, 20091 Comment1 Min Read
    Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Email

    When a file is saved in Windows and then moved to a Linux system the formatting differences can cause a variety of problems. To effectively use these files you will need to change the format from Windows/DOS to Unix. This conversion occurs by simply removing the Windows carriage return characters.

    I have explained how to use the tr command remove these windows carriage returns, but when you have a large amount of files to convert this can become tedious. As a solution to this I have written a BASH script to convert all text files within a directory.

    #!/bin/bash
    
    for file in /directory/to/convert/*
    do
      if [[ -f $file && `file $file | grep text` ]]
      then 
        tr -d '\r' < $file > "$file"_clear
        mv "$file"_clear $file
      fi
    done
    
    Share. Facebook Twitter Pinterest LinkedIn WhatsApp Reddit Email
    Previous ArticleView the status of a long emerge
    Next Article Fix for missing title bar and GNOME panel with Firefox

    Related Posts

    How to test the syntax of a Python script

    Safely and atomically change a symlink target

    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
    © 2025 ThemeSphere. Designed by ThemeSphere.

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