#!/usr/bin/ksh
 ##########################################################################
#
#         Author : Adam Radage
#
#         Copyright : This code is in the public domain.
#
#         Date : 16/07/07
#
#        Usage : ./remove_ctlm.ksh <dir> <dir> .....
#
#        Description : A script to remove Windows tailing ^M Control M characters from files in directories
#                           With arguments <dir> it will process all files in these directories.
#                           It can process any number of directories
#
##########################################################################
#
##########################################################################
if (( $# >= 1 ));then
  for j in "$@"
  do
    DIRNAME=$j
    if ( test -d $DIRNAME ); then
      echo "Checking $DIRNAME"
      for i in `ls $DIRNAME`
      do
        FILNAME=.\/$DIRNAME\/$i
        echo "Processing $FILNAME"
        chmod 750 $FILNAME
        cat $FILNAME|sed '1,$ s///g'>temp
        cp temp $FILNAME
        rm temp
      done
    else
      echo "Directory $DIRNAME does not exist"
    fi
  done
else
  echo "No directory specified"
fi
