#!/bin/sh print_usage() { echo "$(basename $0) -- Translates multiple DOS text file to UNIX." echo "Usage: $(basename $0) dos-text-file" } if [ $# = 0 ]; then print_usage exit 1 fi TMPFILE="/tmp/dos2unix$$" while [ $# -ne 0 ]; do # Checking if input file exist. if [ ! -f $1 ]; then echo "$0: File $1 not found." print_usage exit 1 fi # DOS files lines ends with CR+LF. Unix files lines ends with LF. # Removing CR from DOS file (CR is 0x0D --> 015 in octal notation). tr -d '\015' < $1 > $TMPFILE if [ $? -eq 0 ] ; then # Success mv $TMPFILE $1 fi shift done if [ -f $TMPFILE ]; then rm $TMPFILE fi