- Bash Script: Convert File from DOS to UNIX format

Common problem! If you need to exchange text files between DOS/Windows and Linux, be aware of the "end of line" problem. Under DOS, each line of text ends with CR/LF (Carriage return/Line feed), with LF under Linux. If you edit a DOS text file under Linux, each line will likely end with a strange--looking `M' character;

Below is simple shell script which converts the files in DOS format to Unix format
Feel free to copy and use this code

Source: cat dos_unix.sh
#!/bin/bash

if [ $# -ne 1 ]; then
        echo "Please provide the path of a valid DOS file"
        exit
fi

if [ ! -f "$1" ]; then
        echo "Cannot access file: $1"
        echo "Don't play, provide the vaild file."
        exit
fi

DOSFILE=$1
UNIXFILE=output.unix
CR='\015'

tr -d $CR < $DOSFILE > $UNIXFILE

echo "Done with the conversion"
echo "New output file is: $UNIXFILE"
exit

Continue Reading...


source:http://linuxpoison.blogspot.com/2012/09/135781677519550.html